From 9aea3ced3b1d81536d8ffe5183086c7d75655ccb Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 8 Sep 2020 11:27:32 -0400 Subject: [PATCH] Custom Field Form - Cleanup country/state leftover cruft --- CRM/Custom/Form/ChangeFieldType.php | 1 - CRM/Custom/Form/Field.php | 25 ++++++++----------------- templates/CRM/Custom/Form/Field.tpl | 6 +++--- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/CRM/Custom/Form/ChangeFieldType.php b/CRM/Custom/Form/ChangeFieldType.php index 8ba794c5cc..54f9197ea8 100644 --- a/CRM/Custom/Form/ChangeFieldType.php +++ b/CRM/Custom/Form/ChangeFieldType.php @@ -225,7 +225,6 @@ class CRM_Custom_Form_ChangeFieldType extends CRM_Core_Form { case 'Int': case 'Float': - case 'Int': case 'Money': if (in_array($htmlType, array_keys($singleValueOps))) { unset($singleValueOps[$htmlType]); diff --git a/CRM/Custom/Form/Field.php b/CRM/Custom/Form/Field.php index af6ca363cb..2bbc8e0c07 100644 --- a/CRM/Custom/Form/Field.php +++ b/CRM/Custom/Form/Field.php @@ -158,8 +158,8 @@ class CRM_Custom_Form_Field extends CRM_Core_Form { ['TextArea' => ts('TextArea'), 'RichTextEditor' => ts('Rich Text Editor')], ['Date' => ts('Select Date')], ['Radio' => ts('Radio')], - ['StateProvince' => ts('Select')], - ['Country' => ts('Select')], + ['Select' => ts('Select')], + ['Select' => ts('Select')], ['File' => ts('Select File')], ['Link' => ts('Link')], ['ContactReference' => ts('Autocomplete-Select')], @@ -180,17 +180,14 @@ class CRM_Custom_Form_Field extends CRM_Core_Form { if ($this->_id) { $this->assign('id', $this->_id); $this->_gid = $defaults['custom_group_id']; + $defaultValue = $defaults['default_value'] ?? NULL; //get the value for state or country - if ($defaults['data_type'] == 'StateProvince' && - $stateId = CRM_Utils_Array::value('default_value', $defaults) - ) { - $defaults['default_value'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_StateProvince', $stateId); + if ($defaults['data_type'] == 'StateProvince' && $defaultValue) { + $defaults['default_value'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_StateProvince', $defaultValue); } - elseif ($defaults['data_type'] == 'Country' && - $countryId = CRM_Utils_Array::value('default_value', $defaults) - ) { - $defaults['default_value'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Country', $countryId); + elseif ($defaults['data_type'] == 'Country' && $defaultValue) { + $defaults['default_value'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Country', $defaultValue); } if ($defaults['data_type'] == 'ContactReference' && !empty($defaults['filter'])) { @@ -259,13 +256,6 @@ class CRM_Custom_Form_Field extends CRM_Core_Form { $defaults['is_view'] = 0; } - if (!empty($defaults['html_type'])) { - $dontShowLink = substr($defaults['html_type'], -14) == 'State/Province' || substr($defaults['html_type'], -7) == 'Country' ? 1 : 0; - } - - if (isset($dontShowLink)) { - $this->assign('dontShowLink', $dontShowLink); - } if ($this->_action & CRM_Core_Action::ADD && CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_gid, 'is_multiple', 'id') ) { @@ -330,6 +320,7 @@ class CRM_Custom_Form_Field extends CRM_Core_Form { if ($this->_action == CRM_Core_Action::UPDATE) { $this->freeze('data_type'); if (!empty($this->_values['option_group_id'])) { + $this->assign('hasOptionGroup', TRUE); // Before dev/core#155 we didn't set the is_reserved flag properly, which should be handled by the upgrade script... // but it is still possible that existing installs may have optiongroups linked to custom fields that are marked reserved. $optionGroupParams['id'] = $this->_values['option_group_id']; diff --git a/templates/CRM/Custom/Form/Field.tpl b/templates/CRM/Custom/Form/Field.tpl index fe0d691482..5dd62613b9 100644 --- a/templates/CRM/Custom/Form/Field.tpl +++ b/templates/CRM/Custom/Form/Field.tpl @@ -272,7 +272,7 @@ $("#noteColumns, #noteRows, #noteLength", $form).toggle(dataType === 'Memo'); - $(".crm-custom-field-form-block-serialize", $form).toggle(htmlType === 'Select' || htmlType === 'Country' || htmlType === 'StateProvince'); + $(".crm-custom-field-form-block-serialize", $form).toggle(htmlType === 'Select'); } $('[name^="data_type"]', $form).change(customOptionHtmlType); @@ -282,8 +282,8 @@ }); {/literal} -{* Give link to view/edit choice options if in edit mode and html_type is one of the multiple choice types *} -{if $action eq 2 AND ($form.data_type.value.1.0 eq 'CheckBox' OR ($form.data_type.value.1.0 eq 'Radio' AND $form.data_type.value.0.0 neq 6) OR $form.data_type.value.1.0 eq 'Select' OR ($form.data_type.value.1.0 eq 'Multi-Select' AND $dontShowLink neq 1 ) ) } +{* Give link to view/edit option group *} +{if $action eq 2 && !empty($hasOptionGroup) } -- 2.25.1