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 = [];
27 protected $includesReadOnlyFields;
30 * Set default values for the form.
32 * Default values are retrieved from the database.
34 public function setDefaultValues() {
35 if (!$this->_defaults
) {
36 $this->_defaults
= [];
37 $this->setDefaultsForMetadataDefinedFields();
39 // @todo these should be retrievable from the above function.
40 $this->_defaults
['enableSSL'] = Civi
::settings()->get('enableSSL');
41 $this->_defaults
['verifySSL'] = Civi
::settings()->get('verifySSL');
42 $this->_defaults
['environment'] = CRM_Core_Config
::environment();
43 $this->_defaults
['enableComponents'] = Civi
::settings()->get('enable_components');
46 return $this->_defaults
;
50 * Build the form object.
52 * @throws \CRM_Core_Exception
54 public function buildQuickForm() {
55 CRM_Core_Session
::singleton()->pushUserContext(CRM_Utils_System
::url('civicrm/admin', 'reset=1'));
64 'name' => ts('Cancel'),
68 $this->addFieldsDefinedInSettingsMetadata();
70 if ($this->includesReadOnlyFields
) {
71 CRM_Core_Session
::setStatus(ts("Some fields are loaded as 'readonly' as they have been set (overridden) in civicrm.settings.php."), '', 'info', ['expires' => 0]);
76 * Process the form submission.
78 public function postProcess() {
79 // store the submitted values in an array
80 $params = $this->controller
->exportValues($this->_name
);
82 self
::commonProcess($params);
88 * @todo Document what I do.
90 * @param array $params
91 * @throws \CRM_Core_Exception
93 public function commonProcess(&$params) {
95 foreach (['verifySSL', 'enableSSL'] as $name) {
96 if (isset($params[$name])) {
97 Civi
::settings()->set($name, $params[$name]);
98 unset($params[$name]);
102 $this->saveMetadataDefinedSettings($params);
104 catch (CiviCRM_API3_Exception
$e) {
105 CRM_Core_Session
::setStatus($e->getMessage(), ts('Save Failed'), 'error');
108 $this->filterParamsSetByMetadata($params);
110 $params = CRM_Core_BAO_ConfigSetting
::filterSkipVars($params);
111 if (!empty($params)) {
112 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)) . ')');
115 CRM_Core_Config
::clearDBCache();
116 // This doesn't make a lot of sense to me, but it maintains pre-existing behavior.
117 Civi
::cache('session')->clear();
118 CRM_Utils_System
::flushCache();
119 CRM_Core_Resources
::singleton()->resetCacheCode();
120 $this->rebuildMenu();
122 CRM_Core_Session
::setStatus(" ", ts('Changes Saved'), "success");
125 public function rebuildMenu() {
126 // ensure config is set with new values
127 $config = CRM_Core_Config
::singleton(TRUE, TRUE);
129 // rebuild menu items
130 CRM_Core_Menu
::store();