CRM-15375 - make the setup create metadata for I18n that can be used in the popup
authorSamuel Vanhove <samuel@symbiotic.coop>
Wed, 29 Apr 2015 21:09:12 +0000 (17:09 -0400)
committerSamuel Vanhove <samuel@symbiotic.coop>
Wed, 29 Apr 2015 21:09:12 +0000 (17:09 -0400)
CRM/Core/CodeGen/I18n.php
CRM/Core/CodeGen/Specification.php
CRM/Core/I18n/Form.php
xml/schema/Contribute/ContributionPage.xml
xml/templates/schema_structure.tpl

index 58318ed83ce54fb3bb892f7d2e4f229ff1d853aa..e48ea1e93737dd69a1d728b2665382228cff60d0 100644 (file)
@@ -25,9 +25,11 @@ class CRM_Core_CodeGen_I18n extends CRM_Core_CodeGen_BaseTask {
     echo "Generating CRM_Core_I18n_SchemaStructure...\n";
     $columns = array();
     $indices = array();
+    $widgets = array();
     foreach ($this->tables as $table) {
       if ($table['localizable']) {
         $columns[$table['name']] = array();
+        $widgets[$table['name']] = array();
       }
       else {
         continue;
@@ -35,6 +37,7 @@ class CRM_Core_CodeGen_I18n extends CRM_Core_CodeGen_BaseTask {
       foreach ($table['fields'] as $field) {
         if ($field['localizable']) {
           $columns[$table['name']][$field['name']] = $field['sqlType'];
+          $widgets[$table['name']][$field['name']] = $field['widget'];
         }
       }
       if (isset($table['index'])) {
@@ -50,6 +53,7 @@ class CRM_Core_CodeGen_I18n extends CRM_Core_CodeGen_BaseTask {
 
     $template->assign('columns', $columns);
     $template->assign('indices', $indices);
+    $template->assign('widgets', $widgets);
 
     $template->run('schema_structure.tpl', $this->config->phpCodePath . "/CRM/Core/I18n/SchemaStructure.php");
   }
index 2e197539694b93c8d0f2e5f8ea48be1bab6b32fc..32e2cc586e2403c4064aa16f72203298466dd9ed 100644 (file)
@@ -381,6 +381,21 @@ class CRM_Core_CodeGen_Specification {
         }
       }
     }
+
+    // in multilingual context popup, we need extra information to create appropriate widget
+    if ($fieldXML->localizable) {
+      if (isset($fieldXML->html)) {
+        $field['widget'] = (array) $fieldXML->html;
+      }
+      else {
+        // default
+        $field['widget'] = array('type' => 'Text');
+      }
+      if (isset($fieldXML->required)) {
+        $field['widget']['required'] = $this->value('required', $fieldXML);
+      }
+    }
+
     $field['pseudoconstant'] = $this->value('pseudoconstant', $fieldXML);
     if (!empty($field['pseudoconstant'])) {
       //ok this is a bit long-winded but it gets there & is consistent with above approach
@@ -395,7 +410,7 @@ class CRM_Core_CodeGen_Specification {
         'labelColumn',
         // Non-translated machine name for programmatic lookup. Defaults to 'name' if that column exists
         'nameColumn',
-        // Where clause snippet (will be joined to the rest of the query with AND operator)
+               // Where clause snippet (will be joined to the rest of the query with AND operator)
         'condition',
         // callback funtion incase of static arrays
         'callback',
index d5d528ba67a8ff816f1b053774af0ed5e79b5214..8ea060b2f7143a7293ddf01684167f8f2ac4cda5 100644 (file)
@@ -61,13 +61,36 @@ class CRM_Core_I18n_Form extends CRM_Core_Form {
     $dao->query($query, FALSE);
     $dao->fetch();
 
-    // we want TEXTAREAs for long fields and INPUTs for short ones
-    $this->_structure[$table][$field] == 'text' ? $type = 'textarea' : $type = 'text';
+    // get html type and attributes for this field
+    $widgets = CRM_Core_I18n_SchemaStructure::widgets();
+    $widget = $widgets[$table][$field];
 
+    // attributes
+    $attributes = array('css' => '');
+    if (isset($widget['rows'])) {
+      $attributes['rows'] = $widget['rows'];
+    }
+    if (isset($widget['cols'])) {
+      $attributes['cols'] = $widget['cols'];
+    }
+    // FIXME: should have this
+    $required = !empty($widget['required']);
+    
     $languages = CRM_Core_I18n::languages(TRUE);
     foreach ($this->_locales as $locale) {
-      $this->addElement($type, "{$field}_{$locale}", $languages[$locale], array('class' => 'huge huge12' . ($locale == $tsLocale ? ' default-lang' : '')));
-      $this->_defaults["{$field}_{$locale}"] = $dao->$locale;
+      $name = "{$field}_{$locale}";
+      if ($locale == $tsLocale) {
+        $attributes['class'] .= ' default-lang';
+      }
+      if ($widget['type'] == 'RichTextEditor') {
+        $attributes['click_wysiwyg'] = TRUE;
+        $this->addWysiwyg($name, $languages[$locale], $attributes, $required);
+      }
+      else {
+        $this->add($widget['type'], $name, $languages[$locale], $attributes, $required);
+      }
+
+      $this->_defaults[$name] = $dao->$locale;
     }
 
     $this->addDefaultButtons(ts('Save'), 'next', NULL);
index 6eef6ae8ada3b0625e2647ba07f5b60a2c0727ea..4ddacb7354842c08ab5c5902612df8b3f6022982 100644 (file)
@@ -33,7 +33,7 @@
     <title>Contribution Page Introduction Text</title>
     <type>text</type>
     <html>
-      <type>TextArea</type>
+      <type>RichTextEditor</type>
       <rows>6</rows>
       <cols>50</cols>
     </html>
     <title>Thank-you Text</title>
     <type>text</type>
     <html>
-      <type>TextArea</type>
+      <type>RichTextEditor</type>
       <rows>8</rows>
       <cols>60</cols>
     </html>
     <title>Thank-you Footer</title>
     <type>text</type>
     <html>
-      <type>TextArea</type>
+      <type>RichTextEditor</type>
       <rows>8</rows>
       <cols>60</cols>
     </html>
     <title>Footer Text</title>
     <type>text</type>
     <html>
-      <type>TextArea</type>
+      <type>RichTextEditor</type>
       <rows>6</rows>
       <cols>50</cols>
     </html>
index f94dc95274678887bc6414718ba86fc3dd53c11b..f2ee37e307db2144c4a5f29572f3ef9589161679 100644 (file)
@@ -84,4 +84,24 @@ class CRM_Core_I18n_SchemaStructure
         {rdelim}
         return $result;
     {rdelim}
+    static function &widgets()
+    {ldelim}
+        static $result = null;
+        if (!$result) {ldelim}
+          $result = array(
+            {foreach from=$widgets key=table item=columns}
+              '{$table}' => array(
+                {foreach from=$columns key=column item=widget}
+                  '{$column}' => array(
+                    {foreach from=$widget key=name item=value}
+                      '{$name}' => "{$value}",
+                    {/foreach}
+                  ),
+                {/foreach}
+              ),
+            {/foreach}
+          );
+        {rdelim}
+        return $result;
+    {rdelim}
 {rdelim}