Commit d434f797 authored by totten's avatar totten

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.
parent b72b5fc0
......@@ -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;
}
}
......@@ -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
));
}
}
......@@ -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?
......
......@@ -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(
......
......@@ -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,
),
);
......@@ -63,13 +63,13 @@
<span class="description">{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}</span></td>
</tr>
<tr class="crm-search-setting-form-block-autocompleteContactSearch">
<td class="label">{$form.autocompleteContactSearch.label}</td>
<td>{$form.autocompleteContactSearch.html}<br/>
<td class="label">{$form.contact_autocomplete_options.label}</td>
<td>{$form.contact_autocomplete_options.html}<br/>
<span class="description">{ts}Selected fields will be displayed in back-office autocomplete dropdown search results (Quick Search, etc.). Contact Name is always included.{/ts}</span></td>
</tr>
<tr class="crm-search-setting-form-block-autocompleteContactReference">
<td class="label">{$form.autocompleteContactReference.label}</td>
<td>{$form.autocompleteContactReference.html}<br/>
<td class="label">{$form.contact_reference_options.label}</td>
<td>{$form.contact_reference_options.html}<br/>
<span class="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.{/ts}</span></td>
</tr>
<tr class="crm-search-setting-form-block-search_autocomplete_count">
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment