From c5af82450958853a928942d069f5b61c32d99f0d Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 8 Oct 2018 21:27:33 +0100 Subject: [PATCH] Convert 'Viewing Smart Groups' on admin display preferences to use metadata. This has no functional impact - cleanup only --- CRM/Admin/Form/Preferences/Display.php | 6 +----- CRM/Admin/Form/SettingTrait.php | 27 +++++++++++++++++++++----- settings/Core.setting.php | 5 ++++- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/CRM/Admin/Form/Preferences/Display.php b/CRM/Admin/Form/Preferences/Display.php index 1ad8357260..0a078de443 100644 --- a/CRM/Admin/Form/Preferences/Display.php +++ b/CRM/Admin/Form/Preferences/Display.php @@ -38,6 +38,7 @@ class CRM_Admin_Form_Preferences_Display extends CRM_Admin_Form_Preferences { protected $_settings = array( 'contact_view_options' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, + 'contact_smart_group_display' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, ); public function preProcess() { @@ -46,11 +47,6 @@ class CRM_Admin_Form_Preferences_Display extends CRM_Admin_Form_Preferences { $this->_varNames = array( CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME => array( - 'contact_smart_group_display' => array( - 'html_type' => 'radio', - 'title' => ts('Viewing Smart Groups'), - 'weight' => 2, - ), 'contact_edit_options' => array( 'html_type' => 'checkboxes', 'title' => ts('Editing Contacts'), diff --git a/CRM/Admin/Form/SettingTrait.php b/CRM/Admin/Form/SettingTrait.php index 4ecd397a45..23c1adb039 100644 --- a/CRM/Admin/Form/SettingTrait.php +++ b/CRM/Admin/Form/SettingTrait.php @@ -116,7 +116,8 @@ trait CRM_Admin_Form_SettingTrait { $settingMetaData = $this->getSettingsMetaData(); $descriptions = []; foreach ($settingMetaData as $setting => $props) { - if (isset($props['quick_form_type'])) { + $quickFormType = $this->getQuickFormType($props); + if (isset($quickFormType)) { if (isset($props['pseudoconstant'])) { $options = civicrm_api3('Setting', 'getoptions', [ 'field' => $setting, @@ -131,7 +132,7 @@ trait CRM_Admin_Form_SettingTrait { $this->includesReadOnlyFields = TRUE; } - $add = 'add' . $props['quick_form_type']; + $add = 'add' . $quickFormType; if ($add == 'addElement') { $this->$add( $props['html_type'], @@ -169,7 +170,7 @@ trait CRM_Admin_Form_SettingTrait { $this->add('date', $setting, ts($props['title']), CRM_Core_SelectValues::date(NULL, 'M d')); } else { - $this->$add($setting, ts($props['title'])); + $this->$add($setting, ts($props['title']), $options['values']); } // Migrate to using an array as easier in smart... $descriptions[$setting] = ts($props['description']); @@ -190,7 +191,23 @@ trait CRM_Admin_Form_SettingTrait { $this->assign('settings_fields', $settingMetaData); } - + /** + * Get the quickform type for the given html type. + * + * @param array $spec + * + * @return string + */ + protected function getQuickFormType($spec) { + if (isset($spec['quick_form_type'])) { + return $spec['quick_form_type']; + } + $mapping = [ + 'checkboxes' => 'CheckBoxes', + 'radio' => 'Radio', + ]; + return $mapping[$spec['html_type']]; + } /** * Get the defaults for all fields defined in the metadata. * @@ -204,7 +221,7 @@ trait CRM_Admin_Form_SettingTrait { if (!empty($spec['serialize'])) { $this->_defaults[$setting] = CRM_Core_DAO::unSerializeField($this->_defaults[$setting], $spec['serialize']); } - if ($spec['quick_form_type'] === 'CheckBoxes') { + if ($this->getQuickFormType($spec) === 'CheckBoxes') { $this->_defaults[$setting] = array_fill_keys($this->_defaults[$setting], 1); } } diff --git a/settings/Core.setting.php b/settings/Core.setting.php index 382e554978..661da7fb3d 100644 --- a/settings/Core.setting.php +++ b/settings/Core.setting.php @@ -324,8 +324,11 @@ return array( 'title' => ts('Viewing Smart Groups'), 'is_domain' => 1, 'is_contact' => 0, - 'description' => NULL, + 'description' => ts('Controls display of the smart groups that a contact is part of in each contact\'s "Groups" tab. "Show on Demand" provides the best performance, and is recommended for most sites.'), 'help_text' => NULL, + 'pseudoconstant' => array( + 'optionGroupName' => 'contact_smart_group_display', + ), ), 'smart_group_cache_refresh_mode' => array( 'group_name' => 'CiviCRM Preferences', -- 2.25.1