}
/**
+ * @todo deprecate in favour of setting using metadata.
+ *
* @param $defaults
*/
public function cbsDefaultValues(&$defaults) {
* 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']) {
}
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');
}
}
+ /**
+ * 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.
*/
*/
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);
}
}
'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',