Convert 'Viewing Smart Groups' on admin display preferences to use metadata.
authoreileen <emcnaughton@wikimedia.org>
Mon, 8 Oct 2018 20:27:33 +0000 (21:27 +0100)
committereileen <emcnaughton@wikimedia.org>
Wed, 10 Oct 2018 08:29:13 +0000 (09:29 +0100)
This has no functional impact - cleanup only

CRM/Admin/Form/Preferences/Display.php
CRM/Admin/Form/SettingTrait.php
settings/Core.setting.php

index 1ad83572600fd2c802eadc6ab8c1c4fc569b9a7d..0a078de443b563ba6ea70cad82f409ac5fd3923a 100644 (file)
@@ -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'),
index 4ecd397a459127fdf6404e0aac11e8e87b7d8744..23c1adb039c63080b37f78dd8ebb20f430e8202f 100644 (file)
@@ -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);
       }
     }
index 382e55497844e0a135fc19571d19665974599746..661da7fb3d27fdc303c69221ec98fec6957c72d8 100644 (file)
@@ -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',