Commit 6821aa1d authored by eileen's avatar eileen

Make checkboxes save

parent 601361a3
......@@ -116,6 +116,8 @@ class CRM_Admin_Form_Preferences extends CRM_Core_Form {
}
/**
* @todo deprecate in favour of setting using metadata.
*
* @param $defaults
*/
public function cbsDefaultValues(&$defaults) {
......@@ -257,6 +259,14 @@ class CRM_Admin_Form_Preferences extends CRM_Core_Form {
* Process the form submission.
*/
public function postProcessCommon() {
try {
$this->saveMetadataDefinedSettings($this->_params);
$this->filterParamsSetByMetadata($this->_params);
}
catch (CiviCRM_API3_Exception $e) {
CRM_Core_Session::setStatus($e->getMessage(), ts('Save Failed'), 'error');
}
foreach ($this->_varNames as $groupName => $groupValues) {
foreach ($groupValues as $settingName => $fieldValue) {
switch ($fieldValue['html_type']) {
......
......@@ -145,7 +145,7 @@ class CRM_Admin_Form_Setting extends CRM_Core_Form {
}
try {
$settings = $this->getSettingsToSetByMetadata($params);
civicrm_api3('setting', 'create', $settings);
$this->saveMetadataDefinedSettings($params);
}
catch (CiviCRM_API3_Exception $e) {
CRM_Core_Session::setStatus($e->getMessage(), ts('Save Failed'), 'error');
......
......@@ -87,6 +87,28 @@ trait CRM_Admin_Form_SettingTrait {
}
}
/**
* Get the metadata for a particular field.
*
* @param $setting
* @return mixed
*/
protected function getSettingMetadata($setting) {
return $this->getSettingsMetaData()[$setting];
}
/**
* Get the metadata for a particular field for a particular item.
*
* e.g get 'serialize' key, if exists, for a field.
*
* @param $setting
* @return mixed
*/
protected function getSettingMetadataItem($setting, $item) {
return CRM_Utils_Array::value($item, $this->getSettingsMetaData()[$setting]);
}
/**
* Add fields in the metadata to the template.
*/
......@@ -176,9 +198,30 @@ trait CRM_Admin_Form_SettingTrait {
*/
protected function setDefaultsForMetadataDefinedFields() {
CRM_Core_BAO_ConfigSetting::retrieve($this->_defaults);
foreach ($this->_settings as $setting => $group) {
foreach (array_keys($this->_settings) as $setting) {
$this->_defaults[$setting] = civicrm_api3('setting', 'getvalue', ['name' => $setting]);
$spec = $this->getSettingsMetadata()[$setting];
if (!empty($spec['serialize'])) {
$this->_defaults[$setting] = CRM_Core_DAO::unSerializeField($this->_defaults[$setting], $spec['serialize']);
}
if ($spec['quick_form_type'] === 'CheckBoxes') {
$this->_defaults[$setting] = array_fill_keys($this->_defaults[$setting], 1);
}
}
}
/**
* @param $params
*
*/
protected function saveMetadataDefinedSettings($params) {
$settings = $this->getSettingsToSetByMetadata($params);
foreach ($settings as $setting => $settingValue) {
if ($this->getSettingMetadataItem($setting, 'quick_form_type') === 'CheckBoxes') {
$settings[$setting] = array_keys($settingValue);
}
}
civicrm_api3('setting', 'create', $settings);
}
}
......@@ -54,6 +54,7 @@ return array(
'is_contact' => 0,
'description' => ts("Select the tabs that should be displayed when viewing a contact record. EXAMPLE: If your organization does not keep track of 'Relationships', then un-check this option to simplify the screen display. Tabs for Contributions, Pledges, Memberships, Events, Grants and Cases are also hidden if the corresponding component is not enabled. Go to Administer > System Settings > Enable Components to modify the components which are available for your site."),
'help_text' => NULL,
'serialize' => CRM_Core_DAO::SERIALIZE_SEPARATOR_BOOKEND,
),
'contact_edit_options' => array(
'group_name' => 'CiviCRM Preferences',
......
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