From 94127e7efd80fb6d07304159c9542ff8e675c410 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Wed, 5 Jun 2019 11:38:47 -0400 Subject: [PATCH] Improve handling of 1st option on search prefs --- CRM/Admin/Form/Setting/Search.php | 30 ++++++++++++++++++++---------- settings/Core.setting.php | 2 ++ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/CRM/Admin/Form/Setting/Search.php b/CRM/Admin/Form/Setting/Search.php index d8e5b6ee4f..effb40d68d 100644 --- a/CRM/Admin/Form/Setting/Search.php +++ b/CRM/Admin/Form/Setting/Search.php @@ -61,19 +61,13 @@ class CRM_Admin_Form_Setting_Search extends CRM_Admin_Form_Setting { parent::buildQuickForm(); - // @todo remove the following adds in favour of setting via the settings array (above). - - // Autocomplete for Contact Search (quick search etc.) + // Option 1 can't be unchecked. @see self::enableOptionOne $element = $this->getElement('contact_autocomplete_options'); - $element->_elements[0]->_flagFrozen = TRUE; + $element->_elements[0]->setAttribute('disabled', 'disabled'); - // Autocomplete for Contact Reference (custom fields) + // Option 1 can't be unchecked. @see self::enableOptionOne $element = $this->getElement('contact_reference_options'); - $element->_elements[0]->_flagFrozen = TRUE; - - // Freeze first element of quicksearch options - $element = $this->getElement('quicksearch_options'); - $element->_elements[0]->_flagFrozen = TRUE; + $element->_elements[0]->setAttribute('disabled', 'disabled'); } /** @@ -102,4 +96,20 @@ class CRM_Admin_Form_Setting_Search extends CRM_Admin_Form_Setting { return [1 => ts('Contact Name')] + CRM_Core_OptionGroup::values('contact_reference_options', FALSE, FALSE, TRUE); } + /** + * Presave callback for contact_reference_options and contact_autocomplete_options. + * + * Ensures "1" is always contained in the array. + * + * @param $value + * @return bool + */ + public static function enableOptionOne(&$value) { + $values = (array) CRM_Utils_Array::explodePadded($value); + if (!in_array(1, $values)) { + $value = CRM_Utils_Array::implodePadded(array_merge([1], $values)); + } + return TRUE; + } + } diff --git a/settings/Core.setting.php b/settings/Core.setting.php index bc33c339bf..77dc4cce90 100644 --- a/settings/Core.setting.php +++ b/settings/Core.setting.php @@ -300,6 +300,7 @@ return [ 'description' => ts("Selected fields will be displayed in back-office autocomplete dropdown search results (Quick Search, etc.). Contact Name is always included."), 'help_text' => NULL, 'serialize' => CRM_Core_DAO::SERIALIZE_SEPARATOR_BOOKEND, + 'validate_callback' => 'CRM_Admin_Form_Setting_Search::enableOptionOne', ], 'contact_reference_options' => [ 'group_name' => 'CiviCRM Preferences', @@ -318,6 +319,7 @@ return [ 'description' => 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."), 'help_text' => NULL, 'serialize' => CRM_Core_DAO::SERIALIZE_SEPARATOR_BOOKEND, + 'validate_callback' => 'CRM_Admin_Form_Setting_Search::enableOptionOne', ], 'contact_smart_group_display' => [ 'group_name' => 'CiviCRM Preferences', -- 2.25.1