3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * This class generates form components generic to CiviCRM settings.
21 class CRM_Admin_Form_Setting
extends CRM_Core_Form
{
23 use CRM_Admin_Form_SettingTrait
;
25 protected $_settings = [];
28 * Set default values for the form.
30 * Default values are retrieved from the database.
32 public function setDefaultValues() {
33 if (!$this->_defaults
) {
34 $this->_defaults
= [];
35 $this->setDefaultsForMetadataDefinedFields();
37 // @todo these should be retrievable from the above function.
38 $this->_defaults
['enableSSL'] = Civi
::settings()->get('enableSSL');
39 $this->_defaults
['verifySSL'] = Civi
::settings()->get('verifySSL');
40 $this->_defaults
['environment'] = CRM_Core_Config
::environment();
41 $this->_defaults
['enableComponents'] = Civi
::settings()->get('enable_components');
44 return $this->_defaults
;
48 * Build the form object.
50 * @throws \CRM_Core_Exception
52 public function buildQuickForm() {
53 CRM_Core_Session
::singleton()->pushUserContext(CRM_Utils_System
::url('civicrm/admin', 'reset=1'));
62 'name' => ts('Cancel'),
66 $this->addFieldsDefinedInSettingsMetadata();
70 * Process the form submission.
72 public function postProcess() {
73 // store the submitted values in an array
74 $params = $this->controller
->exportValues($this->_name
);
76 self
::commonProcess($params);
82 * @todo Document what I do.
84 * @param array $params
85 * @throws \CRM_Core_Exception
87 public function commonProcess(&$params) {
89 foreach (['verifySSL', 'enableSSL'] as $name) {
90 if (isset($params[$name])) {
91 Civi
::settings()->set($name, $params[$name]);
92 unset($params[$name]);
96 $this->saveMetadataDefinedSettings($params);
98 catch (CiviCRM_API3_Exception
$e) {
99 CRM_Core_Session
::setStatus($e->getMessage(), ts('Save Failed'), 'error');
102 $this->filterParamsSetByMetadata($params);
104 $params = CRM_Core_BAO_ConfigSetting
::filterSkipVars($params);
105 if (!empty($params)) {
106 throw new CRM_Core_Exception('Unrecognized setting. This may be a config field which has not been properly migrated to a setting. (' . implode(', ', array_keys($params)) . ')');
109 CRM_Core_Config
::clearDBCache();
110 // This doesn't make a lot of sense to me, but it maintains pre-existing behavior.
111 Civi
::cache('session')->clear();
112 CRM_Utils_System
::flushCache();
113 CRM_Core_Resources
::singleton()->resetCacheCode();
114 $this->rebuildMenu();
116 CRM_Core_Session
::setStatus(" ", ts('Changes Saved'), "success");
119 public function rebuildMenu() {
120 // ensure config is set with new values
121 $config = CRM_Core_Config
::singleton(TRUE, TRUE);
123 // rebuild menu items
124 CRM_Core_Menu
::store();