CRM-13497 - Update CodeGen to handle xml mods
authorColeman Watts <coleman@civicrm.org>
Wed, 11 Dec 2013 21:25:44 +0000 (13:25 -0800)
committerColeman Watts <coleman@civicrm.org>
Wed, 11 Dec 2013 21:27:41 +0000 (13:27 -0800)
CRM/Core/CodeGen/Specification.php
xml/templates/dao.tpl

index 4e667336efba4628657d195bf3455907a89198d8..da2a6e6399c39b354cfc4521ee854d6f4afc33fd 100644 (file)
@@ -284,8 +284,10 @@ class CRM_Core_CodeGen_Specification {
       case 'text':
         $field['sqlType'] = $field['phpType'] = $type;
         $field['crmType'] = 'CRM_Utils_Type::T_' . strtoupper($type);
-        $field['rows']    = $this->value('rows', $fieldXML);
-        $field['cols']    = $this->value('cols', $fieldXML);
+        // CRM-13497 see fixme below
+        $field['rows'] = isset($fieldXML->html) ? $this->value('rows', $fieldXML->html) : NULL;
+        $field['cols'] = isset($fieldXML->html) ? $this->value('cols', $fieldXML->html) : NULL;
+        break;
         break;
 
       case 'datetime':
@@ -344,6 +346,26 @@ class CRM_Core_CodeGen_Specification {
     $field['headerPattern'] = $this->value('headerPattern', $fieldXML);
     $field['dataPattern'] = $this->value('dataPattern', $fieldXML);
     $field['uniqueName'] = $this->value('uniqueName', $fieldXML);
+    $field['html'] = $this->value('html', $fieldXML);
+    if (!empty($field['html'])) {
+      $validOptions = array(
+        'type',
+        /* Fixme: prior to CRM-13497 these were in a flat structure
+        // CRM-13497 moved them to be nested within 'html' but there's no point
+        // making that change in the DAOs right now since we are in the process of
+        // moving to docrtine anyway.
+        // So translating from nested xml back to flat structure for now.
+        'rows',
+        'cols',
+        'size', */
+      );
+      $field['html'] = array();
+      foreach ($validOptions as $htmlOption) {
+        if(!empty($fieldXML->html->$htmlOption)){
+          $field['html'][$htmlOption] = $this->value($htmlOption, $fieldXML->html);
+        }
+      }
+    }
     $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
@@ -561,8 +583,8 @@ class CRM_Core_CodeGen_Specification {
    */
   protected function getSize($fieldXML) {
     // Extract from <size> tag if supplied
-    if ($this->value('size', $fieldXML)) {
-      $const = 'CRM_Utils_Type::' . strtoupper($fieldXML->size);
+    if (!empty($fieldXML->html) && $this->value('size', $fieldXML->html)) {
+      $const = 'CRM_Utils_Type::' . strtoupper($fieldXML->html->size);
       if (defined($const)) {
         return $const;
       }
index f6e7ad545a2563f656a2eeb56122a5fc0b196872..270e7ca4949fae4d1eebbf39d5eee60b27c0334a 100644 (file)
@@ -220,6 +220,15 @@ class {$table.className} extends CRM_Core_DAO {ldelim}
 {if $field.FKClassName}
                       'FKClassName' => '{$field.FKClassName}',
 {/if} {* field.FKClassName *}
+{if $field.html}
+  {assign var=htmlOptions value=$field.html}
+  'html' => array(
+{*{$htmlOptions|@print_array}*}
+  {foreach from=$htmlOptions key=optionKey item=optionValue}
+    '{$optionKey}' => '{$optionValue}',
+  {/foreach}
+  ),
+{/if} {* field.html *}
 {if $field.pseudoconstant}
 {assign var=pseudoOptions value=$field.pseudoconstant}
 'pseudoconstant' => array(