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