Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
6b83d5bd | 31 | * @copyright CiviCRM LLC (c) 2004-2019 |
6a488035 TO |
32 | */ |
33 | ||
34 | /** | |
ce064e4f | 35 | * This class generates form components generic to CiviCRM settings. |
6a488035 TO |
36 | */ |
37 | class CRM_Admin_Form_Setting extends CRM_Core_Form { | |
38 | ||
946389fb | 39 | use CRM_Admin_Form_SettingTrait; |
40 | ||
be2fb01f | 41 | protected $_settings = []; |
6a488035 | 42 | |
4dd431ca | 43 | protected $includesReadOnlyFields; |
44 | ||
6a488035 | 45 | /** |
c490a46a | 46 | * Set default values for the form. |
6a488035 | 47 | * |
ee0ce2ef | 48 | * Default values are retrieved from the database. |
6a488035 | 49 | */ |
00be9182 | 50 | public function setDefaultValues() { |
6a488035 | 51 | if (!$this->_defaults) { |
be2fb01f CW |
52 | $this->_defaults = []; |
53 | $formArray = ['Component', 'Localization']; | |
353ffa53 | 54 | $formMode = FALSE; |
6a488035 TO |
55 | if (in_array($this->_name, $formArray)) { |
56 | $formMode = TRUE; | |
57 | } | |
58 | ||
601361a3 | 59 | $this->setDefaultsForMetadataDefinedFields(); |
6a488035 | 60 | |
ec3cc27f | 61 | // @todo these should be retrievable from the above function. |
aaffa79f | 62 | $this->_defaults['enableSSL'] = Civi::settings()->get('enableSSL'); |
63 | $this->_defaults['verifySSL'] = Civi::settings()->get('verifySSL'); | |
f008885c | 64 | $this->_defaults['environment'] = CRM_Core_Config::environment(); |
f4fb2d79 | 65 | $this->_defaults['enableComponents'] = Civi::settings()->get('enable_components'); |
6a488035 TO |
66 | } |
67 | ||
68 | return $this->_defaults; | |
69 | } | |
70 | ||
71 | /** | |
567b2076 | 72 | * Build the form object. |
6a488035 TO |
73 | */ |
74 | public function buildQuickForm() { | |
089360bb | 75 | CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/admin', 'reset=1')); |
be2fb01f | 76 | $this->addButtons([ |
0d48f1cc TO |
77 | [ |
78 | 'type' => 'next', | |
79 | 'name' => ts('Save'), | |
80 | 'isDefault' => TRUE, | |
81 | ], | |
82 | [ | |
83 | 'type' => 'cancel', | |
84 | 'name' => ts('Cancel'), | |
85 | ], | |
86 | ]); | |
6a488035 | 87 | |
e894ae15 | 88 | $this->addFieldsDefinedInSettingsMetadata(); |
4dd431ca | 89 | |
90 | if ($this->includesReadOnlyFields) { | |
be2fb01f | 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]); |
4dd431ca | 92 | } |
6a488035 TO |
93 | } |
94 | ||
95 | /** | |
ee0ce2ef | 96 | * Process the form submission. |
6a488035 TO |
97 | */ |
98 | public function postProcess() { | |
99 | // store the submitted values in an array | |
100 | $params = $this->controller->exportValues($this->_name); | |
101 | ||
102 | self::commonProcess($params); | |
103 | } | |
104 | ||
e0ef6999 | 105 | /** |
5c9ff055 EM |
106 | * Common Process. |
107 | * | |
108 | * @todo Document what I do. | |
109 | * | |
c490a46a | 110 | * @param array $params |
946389fb | 111 | * @throws \CRM_Core_Exception |
e0ef6999 | 112 | */ |
6a488035 TO |
113 | public function commonProcess(&$params) { |
114 | ||
be2fb01f | 115 | foreach (['verifySSL', 'enableSSL'] as $name) { |
5e7f101a | 116 | if (isset($params[$name])) { |
117 | Civi::settings()->set($name, $params[$name]); | |
118 | unset($params[$name]); | |
119 | } | |
6a488035 | 120 | } |
946389fb | 121 | try { |
6821aa1d | 122 | $this->saveMetadataDefinedSettings($params); |
6a488035 | 123 | } |
946389fb | 124 | catch (CiviCRM_API3_Exception $e) { |
125 | CRM_Core_Session::setStatus($e->getMessage(), ts('Save Failed'), 'error'); | |
af962699 TO |
126 | } |
127 | ||
946389fb | 128 | $this->filterParamsSetByMetadata($params); |
129 | ||
7e0c769c TO |
130 | $params = CRM_Core_BAO_ConfigSetting::filterSkipVars($params); |
131 | if (!empty($params)) { | |
946389fb | 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)) . ')'); |
7e0c769c | 133 | } |
b08fb110 CW |
134 | |
135 | CRM_Core_Config::clearDBCache(); | |
0d48f1cc TO |
136 | // This doesn't make a lot of sense to me, but it maintains pre-existing behavior. |
137 | Civi::cache('session')->clear(); | |
b08fb110 CW |
138 | CRM_Utils_System::flushCache(); |
139 | CRM_Core_Resources::singleton()->resetCacheCode(); | |
140 | ||
4481526f | 141 | CRM_Core_Session::setStatus(" ", ts('Changes Saved'), "success"); |
6a488035 TO |
142 | } |
143 | ||
144 | public function rebuildMenu() { | |
145 | // ensure config is set with new values | |
146 | $config = CRM_Core_Config::singleton(TRUE, TRUE); | |
147 | ||
148 | // rebuild menu items | |
149 | CRM_Core_Menu::store(); | |
6a488035 | 150 | } |
96025800 | 151 | |
6a488035 | 152 | } |