Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NFC] Convert some fields on admin display preferences to use metdata #12906

Merged
merged 5 commits into from
Oct 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 3 additions & 15 deletions CRM/Admin/Form/Preferences/Display.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ 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,
'advanced_search_options' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'preserve_activity_tab_filter' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
);

public function preProcess() {
Expand All @@ -46,21 +49,11 @@ public function preProcess() {

$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'),
'weight' => 3,
),
'advanced_search_options' => array(
'html_type' => 'checkboxes',
'title' => ts('Contact Search'),
'weight' => 4,
),
'activity_assignee_notification' => array(
'html_type' => 'checkbox',
'title' => ts('Notify Activity Assignees'),
Expand All @@ -71,11 +64,6 @@ public function preProcess() {
'title' => ts('Include ICal Invite to Activity Assignees'),
'weight' => 6,
),
'preserve_activity_tab_filter' => array(
'html_type' => 'checkbox',
'title' => ts('Preserve activity filters as a user preference'),
'weight' => 7,
),
'contact_ajax_check_similar' => array(
'title' => ts('Check for Similar Contacts'),
'weight' => 8,
Expand Down
46 changes: 33 additions & 13 deletions CRM/Admin/Form/SettingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,39 +116,42 @@ protected function addFieldsDefinedInSettingsMetadata() {
$settingMetaData = $this->getSettingsMetaData();
$descriptions = [];
foreach ($settingMetaData as $setting => $props) {
if (isset($props['quick_form_type'])) {
$quickFormType = $this->getQuickFormType($props);
if (isset($quickFormType)) {
$options = NULL;
if (isset($props['pseudoconstant'])) {
$options = civicrm_api3('Setting', 'getoptions', [
'field' => $setting,
]);
])['values'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the preference for using $options instead of $options['values'] below, but functioncall()['arrayindex'] is messy. $options = $options['values'] would be preferable in my view.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a big fan of that syntax though :-(

}
else {
$options = NULL;
if ($props['type'] === 'Boolean') {
$options = [$props['title'] => $props['name']];
}

//Load input as readonly whose values are overridden in civicrm.settings.php.
if (Civi::settings()->getMandatory($setting)) {
$props['html_attributes']['readonly'] = TRUE;
$this->includesReadOnlyFields = TRUE;
}

$add = 'add' . $props['quick_form_type'];
$add = 'add' . $quickFormType;
if ($add == 'addElement') {
$this->$add(
$props['html_type'],
$setting,
ts($props['title']),
($options !== NULL) ? $options['values'] : CRM_Utils_Array::value('html_attributes', $props, []),
($options !== NULL) ? $options : CRM_Utils_Array::value('html_attributes', $props, []),
($options !== NULL) ? CRM_Utils_Array::value('html_attributes', $props, []) : NULL
);
}
elseif ($add == 'addSelect') {
$this->addElement('select', $setting, ts($props['title']), $options['values'], CRM_Utils_Array::value('html_attributes', $props));
$this->addElement('select', $setting, ts($props['title']), $options, 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, ['  ']);
$this->addCheckBox($setting, ts($props['title']), $options, NULL, CRM_Utils_Array::value('html_attributes', $props), NULL, NULL, ['  ']);
}
elseif ($add == 'addCheckBoxes') {
$options = array_flip($options['values']);
$options = array_flip($options);
$newOptions = [];
foreach ($options as $key => $val) {
$newOptions[$key] = $val;
Expand All @@ -169,7 +172,7 @@ protected function addFieldsDefinedInSettingsMetadata() {
$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);
}
// Migrate to using an array as easier in smart...
$descriptions[$setting] = ts($props['description']);
Expand All @@ -190,7 +193,24 @@ protected function addFieldsDefinedInSettingsMetadata() {
$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',
'checkbox' => 'CheckBox',
'radio' => 'Radio',
];
return $mapping[$spec['html_type']];
}
/**
* Get the defaults for all fields defined in the metadata.
*
Expand All @@ -204,7 +224,7 @@ protected function setDefaultsForMetadataDefinedFields() {
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);
}
}
Expand All @@ -217,7 +237,7 @@ protected function setDefaultsForMetadataDefinedFields() {
protected function saveMetadataDefinedSettings($params) {
$settings = $this->getSettingsToSetByMetadata($params);
foreach ($settings as $setting => $settingValue) {
if ($this->getSettingMetadataItem($setting, 'quick_form_type') === 'CheckBoxes') {
if ($this->getQuickFormType($this->getSettingMetadata($setting)) === 'CheckBoxes') {
$settings[$setting] = array_keys($settingValue);
}
}
Expand Down
31 changes: 18 additions & 13 deletions settings/Core.setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,16 @@
),
'default' => '123456789111214151617',
'add' => '4.1',
'title' => 'Editing Contacts',
'title' => ts('Editing Contacts'),
'is_domain' => 1,
'is_contact' => 0,
'description' => NULL,
'description' => ts('Select the sections that should be included when adding or editing a contact record. EXAMPLE: If your organization does not record Gender and Birth Date for individuals, then simplify the form by un-checking this option. Drag interface allows you to change the order of the panes displayed on contact add/edit screen.'),
'help_text' => NULL,
'serialize' => CRM_Core_DAO::SERIALIZE_SEPARATOR_BOOKEND,
),
'advanced_search_options' => array(
'group_name' => 'CiviCRM Preferences',
'group' => 'core',
'name' => 'advanced_search_options',
'type' => 'String',
'html_type' => 'checkboxes',
Expand All @@ -83,11 +85,11 @@
),
'default' => '123456789101112131516171819',
'add' => '4.1',
'title' => 'Contact Search',
'title' => ts('Contact Search'),
'is_domain' => 1,
'is_contact' => 0,
'description' => NULL,
'help_text' => NULL,
'description' => ts('Select the sections that should be included in the Basic and Advanced Search forms. EXAMPLE: If you don\'t track Relationships - then you do not need this section included in the advanced search form. Simplify the form by un-checking this option.'),
'serialize' => CRM_Core_DAO::SERIALIZE_SEPARATOR_BOOKEND,
),
'user_dashboard_options' => array(
'group_name' => 'CiviCRM Preferences',
Expand Down Expand Up @@ -324,8 +326,11 @@
'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',
Expand Down Expand Up @@ -961,28 +966,28 @@
'group' => 'core',
'name' => 'syncCMSEmail',
'type' => 'Boolean',
'html_type' => 'YesNo',
'quick_form_type' => 'YesNo',
'default' => 1,
'add' => '4.7',
'title' => 'Sync CMS Email',
'title' => ts('Sync CMS Email'),
'is_domain' => 1,
'is_contact' => 0,
'description' => 'If enabled, then CMS email id will be syncronised with CiviCRM contacts\'s primary email.',
'description' => ts('If enabled, then CMS email id will be synchronised with CiviCRM contacts\'s primary email.'),
'help_text' => NULL,
),
'preserve_activity_tab_filter' => array(
'group_name' => 'CiviCRM Preferences',
'group' => 'core',
'name' => 'preserve_activity_tab_filter',
'type' => 'String',
'html_type' => 'Text',
'type' => 'Boolean',
'html_type' => 'checkbox',
'default' => '0',
'add' => '4.7',
'title' => 'Preserve activity filters as a user preference',
'title' => ts('Preserve activity filters as a user preference'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Title markup entries should probably end with a full stop like most of the description entries do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as discussed - leaving full stops off the titles

'is_domain' => 1,
'is_contact' => 0,
'description' => 'When enabled, any filter settings a user selects on the contact\'s Activity tab will be remembered as they visit other contacts',
'help_text' => NULL,
'description' => ts('When enabled, any filter settings a user selects on the contact\'s Activity tab will be remembered as they visit other contacts.'),
),
'do_not_notify_assignees_for' => array(
'group_name' => 'CiviCRM Preferences',
Expand Down
7 changes: 3 additions & 4 deletions templates/CRM/Admin/Form/Preferences/Display.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<tr class="crm-preferences-display-form-block-description">
<td>&nbsp;</td>
<td class="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.{/ts}
{$settings_fields.contact_smart_group_display.description}
</td>
</tr>
<tr class="crm-preferences-display-form-block-contact_edit_options">
Expand Down Expand Up @@ -155,12 +155,11 @@

<tr class="crm-preferences-display-form-block-preserve_activity_tab_filter">
<td class="label"></td>
<td>{$form.preserve_activity_tab_filter.html} {$form.preserve_activity_tab_filter.label}</td>
<td>{$form.preserve_activity_tab_filter.html}</td>
</tr>
<tr class="crm-preferences-display-form-block-description">
<td>&nbsp;</td>
<td class="description">{ts}When enabled, any filter settings a user selects on the contact's Activity tab will be remembered as they visit other contacts.{/ts}
</td>
<td class="description">{$settings_fields.preserve_activity_tab_filter.description}</td>
</tr>

<tr class="crm-preferences-display-form-block-user_dashboard_options">
Expand Down