From fdd11b39436ac6cfe676427a76e397f5e9a4e085 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sun, 5 Apr 2020 21:23:50 -0400 Subject: [PATCH] Update CustomField form with 'serialize' option --- CRM/Core/BAO/CustomField.php | 7 ++++++- CRM/Custom/Form/Field.php | 13 +++++++++++++ templates/CRM/Custom/Form/Field.tpl | 6 ++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/CRM/Core/BAO/CustomField.php b/CRM/Core/BAO/CustomField.php index d9a871d809..9166802f08 100644 --- a/CRM/Core/BAO/CustomField.php +++ b/CRM/Core/BAO/CustomField.php @@ -1891,7 +1891,12 @@ WHERE id IN ( %1, %2 ) $params['date_format'] = Civi::settings()->get('dateInputFormat'); } - if ($htmlType === 'CheckBox' || $htmlType === 'Multi-Select') { + // Checkboxes are always serialized in current schema + if ($htmlType == 'CheckBox') { + $params['serialize'] = CRM_Core_DAO::SERIALIZE_SEPARATOR_BOOKEND; + } + + if (!empty($params['serialize'])) { if (isset($params['default_checkbox_option'])) { $defaultArray = []; foreach (array_keys($params['default_checkbox_option']) as $k => $v) { diff --git a/CRM/Custom/Form/Field.php b/CRM/Custom/Form/Field.php index 0258e06816..e61d23ed80 100644 --- a/CRM/Custom/Form/Field.php +++ b/CRM/Custom/Form/Field.php @@ -327,6 +327,8 @@ class CRM_Custom_Form_Field extends CRM_Core_Form { 'return' => ['title'], ]; + $this->add('checkbox', 'serialize', ts('Multi-Select')); + if ($this->_action == CRM_Core_Action::UPDATE) { $this->freeze('data_type'); if (!empty($this->_values['option_group_id'])) { @@ -948,6 +950,17 @@ AND option_group_id = %2"; $params['is_search_range'] = 0; } + // Serialization cannot be changed on update + if ($this->_id) { + unset($params['serialize']); + } + elseif (strpos($params['html_type'], 'Select') === 0) { + $params['serialize'] = $params['serialize'] ? CRM_Core_DAO::SERIALIZE_SEPARATOR_BOOKEND : 'null'; + } + else { + $params['serialize'] = $params['html_type'] == 'CheckBox' ? CRM_Core_DAO::SERIALIZE_SEPARATOR_BOOKEND : 'null'; + } + $filter = 'null'; if ($dataTypeKey == 11 && !empty($params['filter_selected'])) { if ($params['filter_selected'] == 'Advance' && trim(CRM_Utils_Array::value('filter', $params))) { diff --git a/templates/CRM/Custom/Form/Field.tpl b/templates/CRM/Custom/Form/Field.tpl index 040dc348cb..83a8dd57e3 100644 --- a/templates/CRM/Custom/Form/Field.tpl +++ b/templates/CRM/Custom/Form/Field.tpl @@ -34,6 +34,10 @@ {/if} + + {$form.serialize.label} + {$form.serialize.html} + {if $form.in_selector} {$form.in_selector.label} @@ -262,6 +266,8 @@ $("#textLength", $form).toggle(dataType === 'String'); $("#noteColumns, #noteRows, #noteLength", $form).toggle(dataType === 'Memo'); + + $(".crm-custom-field-form-block-serialize", $form).toggle(htmlType === 'Select' || htmlType === 'Country' || htmlType === 'StateProvince'); } $('[name^="data_type"]', $form).change(customOptionHtmlType); -- 2.25.1