3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2019
35 * This class generates form components generic to CiviCRM settings.
37 class CRM_Admin_Form_Setting
extends CRM_Core_Form
{
39 use CRM_Admin_Form_SettingTrait
;
41 protected $_settings = [];
43 protected $includesReadOnlyFields;
46 * Set default values for the form.
48 * Default values are retrieved from the database.
50 public function setDefaultValues() {
51 if (!$this->_defaults
) {
52 $this->_defaults
= [];
53 $formArray = ['Component', 'Localization'];
55 if (in_array($this->_name
, $formArray)) {
59 $this->setDefaultsForMetadataDefinedFields();
61 // @todo these should be retrievable from the above function.
62 $this->_defaults
['enableSSL'] = Civi
::settings()->get('enableSSL');
63 $this->_defaults
['verifySSL'] = Civi
::settings()->get('verifySSL');
64 $this->_defaults
['environment'] = CRM_Core_Config
::environment();
65 $this->_defaults
['enableComponents'] = Civi
::settings()->get('enable_components');
68 return $this->_defaults
;
72 * Build the form object.
74 public function buildQuickForm() {
75 CRM_Core_Session
::singleton()->pushUserContext(CRM_Utils_System
::url('civicrm/admin', 'reset=1'));
84 'name' => ts('Cancel'),
88 $this->addFieldsDefinedInSettingsMetadata();
90 if ($this->includesReadOnlyFields
) {
91 CRM_Core_Session
::setStatus(ts("Some fields are loaded as 'readonly' as they have been set (overridden) in civicrm.settings.php."), '', 'info', ['expires' => 0]);
96 * Process the form submission.
98 public function postProcess() {
99 // store the submitted values in an array
100 $params = $this->controller
->exportValues($this->_name
);
102 self
::commonProcess($params);
108 * @todo Document what I do.
110 * @param array $params
111 * @throws \CRM_Core_Exception
113 public function commonProcess(&$params) {
115 foreach (['verifySSL', 'enableSSL'] as $name) {
116 if (isset($params[$name])) {
117 Civi
::settings()->set($name, $params[$name]);
118 unset($params[$name]);
122 $this->saveMetadataDefinedSettings($params);
124 catch (CiviCRM_API3_Exception
$e) {
125 CRM_Core_Session
::setStatus($e->getMessage(), ts('Save Failed'), 'error');
128 $this->filterParamsSetByMetadata($params);
130 $params = CRM_Core_BAO_ConfigSetting
::filterSkipVars($params);
131 if (!empty($params)) {
132 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)) . ')');
135 CRM_Core_Config
::clearDBCache();
136 // This doesn't make a lot of sense to me, but it maintains pre-existing behavior.
137 Civi
::cache('session')->clear();
138 CRM_Utils_System
::flushCache();
139 CRM_Core_Resources
::singleton()->resetCacheCode();
141 CRM_Core_Session
::setStatus(" ", ts('Changes Saved'), "success");
144 public function rebuildMenu() {
145 // ensure config is set with new values
146 $config = CRM_Core_Config
::singleton(TRUE, TRUE);
148 // rebuild menu items
149 CRM_Core_Menu
::store();