Commit | Line | Data |
---|---|---|
f167c7a9 | 1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
f167c7a9 | 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 | | |
f167c7a9 | 9 | +--------------------------------------------------------------------+ |
10 | */ | |
11 | ||
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
f167c7a9 | 16 | */ |
17 | ||
18 | /** | |
19 | * Generic metadata based settings form. | |
20 | * | |
21 | * The form filter will determine the settings displayed. | |
22 | */ | |
23 | class CRM_Admin_Form_Generic extends CRM_Core_Form { | |
24 | use CRM_Admin_Form_SettingTrait; | |
25 | ||
26 | protected $_settings = []; | |
27 | protected $includesReadOnlyFields = FALSE; | |
28 | public $_defaults = []; | |
29 | ||
30 | /** | |
31 | * Get the tpl file name. | |
32 | * | |
33 | * @return string | |
34 | */ | |
35 | public function getTemplateFileName() { | |
36 | return 'CRM/Form/basicForm.tpl'; | |
37 | } | |
38 | ||
39 | /** | |
40 | * Set default values for the form. | |
41 | * | |
42 | * Default values are retrieved from the database. | |
43 | */ | |
44 | public function setDefaultValues() { | |
45 | $this->setDefaultsForMetadataDefinedFields(); | |
46 | return $this->_defaults; | |
47 | } | |
51f35276 | 48 | |
f167c7a9 | 49 | /** |
50 | * Build the form object. | |
51 | */ | |
52 | public function buildQuickForm() { | |
51f35276 | 53 | $filter = $this->getSettingPageFilter(); |
f167c7a9 | 54 | $settings = civicrm_api3('Setting', 'getfields', [])['values']; |
55 | foreach ($settings as $key => $setting) { | |
56 | if (isset($setting['settings_pages'][$filter])) { | |
57 | $this->_settings[$key] = $setting; | |
58 | } | |
59 | } | |
51f35276 | 60 | |
f167c7a9 | 61 | $this->addFieldsDefinedInSettingsMetadata(); |
62 | ||
63 | // @todo look at sharing the code below in the settings trait. | |
64 | if ($this->includesReadOnlyFields) { | |
be2fb01f | 65 | CRM_Core_Session::setStatus(ts("Some fields are loaded as 'readonly' as they have been set (overridden) in civicrm.settings.php."), '', 'info', ['expires' => 0]); |
f167c7a9 | 66 | } |
67 | ||
68 | // @todo - do we still like this redirect? | |
69 | CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/admin', 'reset=1')); | |
be2fb01f | 70 | $this->addButtons([ |
0d48f1cc TO |
71 | [ |
72 | 'type' => 'next', | |
73 | 'name' => ts('Save'), | |
74 | 'isDefault' => TRUE, | |
75 | ], | |
76 | [ | |
77 | 'type' => 'cancel', | |
78 | 'name' => ts('Cancel'), | |
79 | ], | |
80 | ]); | |
f167c7a9 | 81 | } |
82 | ||
83 | /** | |
84 | * Process the form submission. | |
85 | */ | |
86 | public function postProcess() { | |
87 | $params = $this->controller->exportValues($this->_name); | |
88 | try { | |
89 | $this->saveMetadataDefinedSettings($params); | |
90 | } | |
91 | catch (CiviCRM_API3_Exception $e) { | |
92 | CRM_Core_Session::setStatus($e->getMessage(), ts('Save Failed'), 'error'); | |
93 | } | |
94 | } | |
95 | ||
96 | } |