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 $formArray = ['Component', 'Localization'];
39 if (in_array($this->_name
, $formArray)) {
43 $this->setDefaultsForMetadataDefinedFields();
45 // @todo these should be retrievable from the above function.
46 $this->_defaults
['enableSSL'] = Civi
::settings()->get('enableSSL');
47 $this->_defaults
['verifySSL'] = Civi
::settings()->get('verifySSL');
48 $this->_defaults
['environment'] = CRM_Core_Config
::environment();
49 $this->_defaults
['enableComponents'] = Civi
::settings()->get('enable_components');
52 return $this->_defaults
;
56 * Build the form object.
58 public function buildQuickForm() {
59 CRM_Core_Session
::singleton()->pushUserContext(CRM_Utils_System
::url('civicrm/admin', 'reset=1'));
68 'name' => ts('Cancel'),
72 $this->addFieldsDefinedInSettingsMetadata();
74 if ($this->includesReadOnlyFields
) {
75 CRM_Core_Session
::setStatus(ts("Some fields are loaded as 'readonly' as they have been set (overridden) in civicrm.settings.php."), '', 'info', ['expires' => 0]);
80 * Process the form submission.
82 public function postProcess() {
83 // store the submitted values in an array
84 $params = $this->controller
->exportValues($this->_name
);
86 self
::commonProcess($params);
92 * @todo Document what I do.
94 * @param array $params
95 * @throws \CRM_Core_Exception
97 public function commonProcess(&$params) {
99 foreach (['verifySSL', 'enableSSL'] as $name) {
100 if (isset($params[$name])) {
101 Civi
::settings()->set($name, $params[$name]);
102 unset($params[$name]);
106 $this->saveMetadataDefinedSettings($params);
108 catch (CiviCRM_API3_Exception
$e) {
109 CRM_Core_Session
::setStatus($e->getMessage(), ts('Save Failed'), 'error');
112 $this->filterParamsSetByMetadata($params);
114 $params = CRM_Core_BAO_ConfigSetting
::filterSkipVars($params);
115 if (!empty($params)) {
116 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)) . ')');
119 CRM_Core_Config
::clearDBCache();
120 // This doesn't make a lot of sense to me, but it maintains pre-existing behavior.
121 Civi
::cache('session')->clear();
122 CRM_Utils_System
::flushCache();
123 CRM_Core_Resources
::singleton()->resetCacheCode();
125 CRM_Core_Session
::setStatus(" ", ts('Changes Saved'), "success");
128 public function rebuildMenu() {
129 // ensure config is set with new values
130 $config = CRM_Core_Config
::singleton(TRUE, TRUE);
132 // rebuild menu items
133 CRM_Core_Menu
::store();