From 313df5eec4252eb044a8adcb368cf6d013427acb Mon Sep 17 00:00:00 2001 From: Samuel Vanhove Date: Wed, 29 Apr 2015 17:09:12 -0400 Subject: [PATCH] CRM-15375 - make the setup create metadata for I18n that can be used in the popup --- CRM/Core/CodeGen/I18n.php | 4 +++ CRM/Core/CodeGen/Specification.php | 17 +++++++++++- CRM/Core/I18n/Form.php | 31 +++++++++++++++++++--- xml/schema/Contribute/ContributionPage.xml | 8 +++--- xml/templates/schema_structure.tpl | 20 ++++++++++++++ 5 files changed, 71 insertions(+), 9 deletions(-) diff --git a/CRM/Core/CodeGen/I18n.php b/CRM/Core/CodeGen/I18n.php index 58318ed83c..e48ea1e937 100644 --- a/CRM/Core/CodeGen/I18n.php +++ b/CRM/Core/CodeGen/I18n.php @@ -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"); } diff --git a/CRM/Core/CodeGen/Specification.php b/CRM/Core/CodeGen/Specification.php index 2e19753969..32e2cc586e 100644 --- a/CRM/Core/CodeGen/Specification.php +++ b/CRM/Core/CodeGen/Specification.php @@ -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', diff --git a/CRM/Core/I18n/Form.php b/CRM/Core/I18n/Form.php index d5d528ba67..8ea060b2f7 100644 --- a/CRM/Core/I18n/Form.php +++ b/CRM/Core/I18n/Form.php @@ -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); diff --git a/xml/schema/Contribute/ContributionPage.xml b/xml/schema/Contribute/ContributionPage.xml index 6eef6ae8ad..4ddacb7354 100644 --- a/xml/schema/Contribute/ContributionPage.xml +++ b/xml/schema/Contribute/ContributionPage.xml @@ -33,7 +33,7 @@ Contribution Page Introduction Text text - TextArea + RichTextEditor 6 50 @@ -249,7 +249,7 @@ Thank-you Text text - TextArea + RichTextEditor 8 60 @@ -262,7 +262,7 @@ Thank-you Footer text - TextArea + RichTextEditor 8 60 @@ -357,7 +357,7 @@ Footer Text text - TextArea + RichTextEditor 6 50 diff --git a/xml/templates/schema_structure.tpl b/xml/templates/schema_structure.tpl index f94dc95274..f2ee37e307 100644 --- a/xml/templates/schema_structure.tpl +++ b/xml/templates/schema_structure.tpl @@ -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} -- 2.25.1