From d434f797170a1813e26a1ff000ea334d4487fd19 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 8 Sep 2015 23:18:34 -0700 Subject: [PATCH] CRM-16373 - Search Settings - Fix dupes (eg contact_reference_options/autocompleteContactReference) Note: * The `autocompleteContactReference` and `autocompleteContactSearch` settings don't seem to be really stored as such. * The form includes various hacks which effectively saves these fields in `contact_reference_options` and `contact_autocomplete_options`. * At runtime, the application logic checks for `contact_reference_options` and `contact_autocomplete_options`. * This situation predates the declarations of `autocompleteContactReference` and `autocompleteContactSearch` in `Search.setting.php`. It seems likely that these settings have never been useful. The fields still have some hacks, but they should be a bit easier to read/trace/grep. --- CRM/Admin/Form/Setting.php | 115 ++++++++++---------- CRM/Admin/Form/Setting/Search.php | 46 ++++---- CRM/Core/BAO/ConfigSetting.php | 1 - settings/Core.setting.php | 18 +-- settings/Search.setting.php | 38 ------- templates/CRM/Admin/Form/Setting/Search.tpl | 8 +- 6 files changed, 100 insertions(+), 126 deletions(-) diff --git a/CRM/Admin/Form/Setting.php b/CRM/Admin/Form/Setting.php index 2e1aed0fb9..60625eb657 100644 --- a/CRM/Admin/Form/Setting.php +++ b/CRM/Admin/Form/Setting.php @@ -54,39 +54,6 @@ class CRM_Admin_Form_Setting extends CRM_Core_Form { CRM_Core_BAO_ConfigSetting::retrieve($this->_defaults); - $list = array_flip(CRM_Core_OptionGroup::values('contact_autocomplete_options', - FALSE, FALSE, TRUE, NULL, 'name' - )); - - $cRlist = array_flip(CRM_Core_OptionGroup::values('contact_reference_options', - FALSE, FALSE, TRUE, NULL, 'name' - )); - - $listEnabled = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, - 'contact_autocomplete_options' - ); - $cRlistEnabled = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, - 'contact_reference_options' - ); - - $autoSearchFields = array(); - if (!empty($list) && !empty($listEnabled)) { - $autoSearchFields = array_combine($list, $listEnabled); - } - - $cRSearchFields = array(); - if (!empty($cRlist) && !empty($cRlistEnabled)) { - $cRSearchFields = array_combine($cRlist, $cRlistEnabled); - } - - //Set defaults for autocomplete and contact reference options - $this->_defaults['autocompleteContactSearch'] = array( - '1' => 1, - ) + $autoSearchFields; - $this->_defaults['autocompleteContactReference'] = array( - '1' => 1, - ) + $cRSearchFields; - // we can handle all the ones defined in the metadata here. Others to be converted foreach ($this->_settings as $setting => $group) { $settingMetaData = civicrm_api('setting', 'getfields', array('version' => 3, 'name' => $setting)); @@ -99,6 +66,8 @@ class CRM_Admin_Form_Setting extends CRM_Core_Form { ); } + $this->_defaults['contact_autocomplete_options'] = self::getAutocompleteContactSearch(); + $this->_defaults['contact_reference_options'] = self::getAutocompleteContactReference(); $this->_defaults['enableSSL'] = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'enableSSL'); $this->_defaults['verifySSL'] = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'verifySSL'); $this->_defaults['enableComponents'] = Civi::settings()->get('enable_components'); @@ -154,6 +123,9 @@ class CRM_Admin_Form_Setting extends CRM_Core_Form { elseif ($add == 'addSelect') { $this->addElement('select', $setting, ts($props['title']), $options['values'], CRM_Utils_Array::value('html_attributes', $props)); } + elseif ($add == 'addCheckBox') { + $this->addCheckBox($setting, ts($props['title']), $options['values'], NULL, CRM_Utils_Array::value('html_attributes', $props), NULL, NULL, array('  ')); + } elseif ($add == 'addChainSelect') { $this->addChainSelect($setting, array( 'label' => ts($props['title']), @@ -205,31 +177,17 @@ class CRM_Admin_Form_Setting extends CRM_Core_Form { public function commonProcess(&$params) { // save autocomplete search options - if (!empty($params['autocompleteContactSearch'])) { - $value = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, - array_keys($params['autocompleteContactSearch']) - ) . CRM_Core_DAO::VALUE_SEPARATOR; - - CRM_Core_BAO_Setting::setItem($value, - CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, - 'contact_autocomplete_options' - ); - - unset($params['autocompleteContactSearch']); + if (!empty($params['contact_autocomplete_options'])) { + Civi::settings()->set('contact_autocomplete_options', + CRM_Utils_Array::implodePadded(array_keys($params['contact_autocomplete_options']))); + unset($params['contact_autocomplete_options']); } // save autocomplete contact reference options - if (!empty($params['autocompleteContactReference'])) { - $value = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, - array_keys($params['autocompleteContactReference']) - ) . CRM_Core_DAO::VALUE_SEPARATOR; - - CRM_Core_BAO_Setting::setItem($value, - CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, - 'contact_reference_options' - ); - - unset($params['autocompleteContactReference']); + if (!empty($params['contact_reference_options'])) { + Civi::settings()->set('contact_reference_options', + CRM_Utils_Array::implodePadded(array_keys($params['contact_reference_options']))); + unset($params['contact_reference_options']); } // save components to be enabled @@ -292,4 +250,51 @@ class CRM_Admin_Form_Setting extends CRM_Core_Form { @unlink($configFile); } + /** + * Ugh, this shouldn't exist. + * + * Get the selected values of "contact_reference_options" formatted for checkboxes. + * + * @return array + */ + public static function getAutocompleteContactReference() { + $cRlist = array_flip(CRM_Core_OptionGroup::values('contact_reference_options', + FALSE, FALSE, TRUE, NULL, 'name' + )); + $cRlistEnabled = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, + 'contact_reference_options' + ); + $cRSearchFields = array(); + if (!empty($cRlist) && !empty($cRlistEnabled)) { + $cRSearchFields = array_combine($cRlist, $cRlistEnabled); + } + return array( + '1' => 1, + ) + $cRSearchFields; + } + + /** + * Ugh, this shouldn't exist. + * + * Get the selected values of "contact_autocomplete_options" formatted for checkboxes. + * + * @return array + */ + public static function getAutocompleteContactSearch() { + $list = array_flip(CRM_Core_OptionGroup::values('contact_autocomplete_options', + FALSE, FALSE, TRUE, NULL, 'name' + )); + $listEnabled = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, + 'contact_autocomplete_options' + ); + $autoSearchFields = array(); + if (!empty($list) && !empty($listEnabled)) { + $autoSearchFields = array_combine($list, $listEnabled); + } + //Set defaults for autocomplete and contact reference options + return array( + '1' => 1, + ) + $autoSearchFields; + } + } diff --git a/CRM/Admin/Form/Setting/Search.php b/CRM/Admin/Form/Setting/Search.php index 47fc581a0a..66bb8f7a88 100644 --- a/CRM/Admin/Form/Setting/Search.php +++ b/CRM/Admin/Form/Setting/Search.php @@ -38,6 +38,8 @@ class CRM_Admin_Form_Setting_Search extends CRM_Admin_Form_Setting { protected $_settings = array( + 'contact_reference_options' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME, + 'contact_autocomplete_options' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME, 'search_autocomplete_count' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME, 'enable_innodb_fts' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME, 'includeWildCardInName' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME, @@ -55,33 +57,28 @@ class CRM_Admin_Form_Setting_Search extends CRM_Admin_Form_Setting { public function buildQuickForm() { CRM_Utils_System::setTitle(ts('Settings - Search Preferences')); + parent::buildQuickForm(); + // @todo remove the following adds in favour of setting via the settings array (above). // Autocomplete for Contact Search (quick search etc.) - $options = array( - ts('Contact Name') => 1, - ) + array_flip(CRM_Core_OptionGroup::values('contact_autocomplete_options', - FALSE, FALSE, TRUE - )); - $this->addCheckBox('autocompleteContactSearch', ts('Autocomplete Contact Search'), $options, - NULL, NULL, NULL, NULL, array('  ') - ); - $element = $this->getElement('autocompleteContactSearch'); + $element = $this->getElement('contact_autocomplete_options'); $element->_elements[0]->_flagFrozen = TRUE; // Autocomplete for Contact Reference (custom fields) - $optionsCR = array( - ts('Contact Name') => 1, - ) + array_flip(CRM_Core_OptionGroup::values('contact_reference_options', - FALSE, FALSE, TRUE - )); - $this->addCheckBox('autocompleteContactReference', ts('Contact Reference Options'), $optionsCR, - NULL, NULL, NULL, NULL, array('  ') - ); - $element = $this->getElement('autocompleteContactReference'); + $element = $this->getElement('contact_reference_options'); $element->_elements[0]->_flagFrozen = TRUE; + } - parent::buildQuickForm(); + /** + * @return array + */ + public static function getContactAutocompleteOptions() { + return array( + ts('Contact Name') => 1, + ) + array_flip(CRM_Core_OptionGroup::values('contact_autocomplete_options', + FALSE, FALSE, TRUE + )); } /** @@ -96,4 +93,15 @@ class CRM_Admin_Form_Setting_Search extends CRM_Admin_Form_Setting { )); } + /** + * @return array + */ + public static function getContactReferenceOptions() { + return array( + ts('Contact Name') => 1, + ) + array_flip(CRM_Core_OptionGroup::values('contact_reference_options', + FALSE, FALSE, TRUE + )); + } + } diff --git a/CRM/Core/BAO/ConfigSetting.php b/CRM/Core/BAO/ConfigSetting.php index de61ec0eee..9045c03c73 100644 --- a/CRM/Core/BAO/ConfigSetting.php +++ b/CRM/Core/BAO/ConfigSetting.php @@ -129,7 +129,6 @@ class CRM_Core_BAO_ConfigSetting { * @param \Civi\Core\SettingsBag $settings * @param string $activatedLocales * Imploded list of locales which are supported in the DB. - * @return array */ public static function applyLocale($settings, $activatedLocales) { // are we in a multi-language setup? diff --git a/settings/Core.setting.php b/settings/Core.setting.php index 8edc5c20eb..966b7945ea 100644 --- a/settings/Core.setting.php +++ b/settings/Core.setting.php @@ -251,16 +251,16 @@ return array( 'group' => 'core', 'name' => 'contact_autocomplete_options', 'type' => 'String', - 'html_type' => 'checkboxes', + 'quick_form_type' => 'CheckBox', 'pseudoconstant' => array( - 'optionGroupName' => 'contact_autocomplete_options', + 'callback' => 'CRM_Admin_Form_Setting_Search::getContactAutocompleteOptions', ), - 'default' => '1234567', + 'default' => '12', 'add' => '4.1', - 'title' => 'Contact Reference Autocomplete Options', + 'title' => 'Autocomplete Contact Search', 'is_domain' => 1, 'is_contact' => 0, - 'description' => NULL, + 'description' => "Selected fields will be displayed in back-office autocomplete dropdown search results (Quick Search, etc.). Contact Name is always included.", 'help_text' => NULL, ), 'contact_reference_options' => array( @@ -268,16 +268,16 @@ return array( 'group' => 'core', 'name' => 'contact_reference_options', 'type' => 'String', - 'html_type' => 'checkboxes', + 'quick_form_type' => 'CheckBox', 'pseudoconstant' => array( - 'optionGroupName' => 'contact_reference_options', + 'callback' => 'CRM_Admin_Form_Setting_Search::getContactReferenceOptions', ), - 'default' => '1234567', + 'default' => '12', 'add' => '4.1', 'title' => 'Contact Reference Options', 'is_domain' => 1, 'is_contact' => 0, - 'description' => NULL, + 'description' => "Selected fields will be displayed in autocomplete dropdown search results for 'Contact Reference' custom fields. Contact Name is always included. NOTE: You must assign 'access contact reference fields' permission to the anonymous role if you want to use custom contact reference fields in profiles on public pages. For most situations, you should use the 'Limit List to Group' setting when configuring a contact reference field which will be used in public forms to prevent exposing your entire contact list.", 'help_text' => NULL, ), 'max_attachments' => array( diff --git a/settings/Search.setting.php b/settings/Search.setting.php index 7cb0d454df..b83d6330d9 100644 --- a/settings/Search.setting.php +++ b/settings/Search.setting.php @@ -214,42 +214,4 @@ return array( 'description' => 'If set, this will be the default profile used for contact search.', 'help_text' => NULL, ), - 'autocompleteContactSearch' => array( - 'group_name' => 'Search Preferences', - 'group' => 'Search Preferences', - 'name' => 'autocompleteContactSearch', - 'prefetch' => 1, - // prefetch causes it to be cached in config settings. Usually this is a transitional setting. Some things like urls are permanent. Remove this comment if you have assessed & it should be permanent - 'config_only' => 1, - //@todo - see https://wiki.civicrm.org/confluence/display/CRMDOC/Settings+Reference#SettingsReference-Convertingaconfigobjecttoasetting on removing this deprecated value - 'type' => 'Integer', - 'quick_form_type' => 'CheckBox', - 'default' => 1, - 'add' => '4.6', - 'title' => 'Autocomplete Contact Search', - 'pseudoconstant' => array('optionGroupName' => 'contact_autocomplete_options'), - 'is_domain' => 1, - 'is_contact' => 0, - 'description' => "Selected fields will be displayed in back-office autocomplete dropdown search results (Quick Search, etc.). Contact Name is always included.", - 'help_text' => NULL, - ), - 'autocompleteContactReference' => array( - 'group_name' => 'Search Preferences', - 'group' => 'Search Preferences', - 'name' => 'autocompleteContactReference', - 'prefetch' => 1, - // prefetch causes it to be cached in config settings. Usually this is a transitional setting. Some things like urls are permanent. Remove this comment if you have assessed & it should be permanent - 'config_only' => 1, - //@todo - see https://wiki.civicrm.org/confluence/display/CRMDOC/Settings+Reference#SettingsReference-Convertingaconfigobjecttoasetting on removing this deprecated value - 'type' => 'Integer', - 'quick_form_type' => 'CheckBox', - 'default' => 1, - 'add' => '4.6', - 'title' => 'Contact Reference Options', - 'pseudoconstant' => array('optionGroupName' => 'contact_reference_options'), - 'is_domain' => 1, - 'is_contact' => 0, - 'description' => "Selected fields will be displayed in autocomplete dropdown search results for 'Contact Reference' custom fields. Contact Name is always included. NOTE: You must assign 'access contact reference fields' permission to the anonymous role if you want to use custom contact reference fields in profiles on public pages. For most situations, you should use the 'Limit List to Group' setting when configuring a contact reference field which will be used in public forms to prevent exposing your entire contact list.", - 'help_text' => NULL, - ), ); diff --git a/templates/CRM/Admin/Form/Setting/Search.tpl b/templates/CRM/Admin/Form/Setting/Search.tpl index 15a7151904..ab0d5926b7 100644 --- a/templates/CRM/Admin/Form/Setting/Search.tpl +++ b/templates/CRM/Admin/Form/Setting/Search.tpl @@ -63,13 +63,13 @@ {ts}The number of minutes to cache smart group contacts. We strongly recommend that this value be greater than zero, since a value of zero means no caching at all. If your contact data changes frequently, you should set this value to at least 5 minutes.{/ts} - {$form.autocompleteContactSearch.label} - {$form.autocompleteContactSearch.html}
+ {$form.contact_autocomplete_options.label} + {$form.contact_autocomplete_options.html}
{ts}Selected fields will be displayed in back-office autocomplete dropdown search results (Quick Search, etc.). Contact Name is always included.{/ts} - {$form.autocompleteContactReference.label} - {$form.autocompleteContactReference.html}
+ {$form.contact_reference_options.label} + {$form.contact_reference_options.html}
{ts}Selected fields will be displayed in autocomplete dropdown search results for 'Contact Reference' custom fields. Contact Name is always included. NOTE: You must assign 'access contact reference fields' permission to the anonymous role if you want to use custom contact reference fields in profiles on public pages. For most situations, you should use the 'Limit List to Group' setting when configuring a contact reference field which will be used in public forms to prevent exposing your entire contact list.{/ts} -- 2.25.1