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 * Generic metadata based settings form.
21 * The form filter will determine the settings displayed.
23 class CRM_Admin_Form_Generic
extends CRM_Core_Form
{
24 use CRM_Admin_Form_SettingTrait
;
26 protected $_settings = [];
27 protected $includesReadOnlyFields = FALSE;
28 public $_defaults = [];
31 * Get the tpl file name.
35 public function getTemplateFileName() {
36 return 'CRM/Form/basicForm.tpl';
40 * Set default values for the form.
42 * Default values are retrieved from the database.
44 public function setDefaultValues() {
45 $this->setDefaultsForMetadataDefinedFields();
46 return $this->_defaults
;
50 * Build the form object.
52 public function buildQuickForm() {
53 $filter = $this->getSettingPageFilter();
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;
61 $this->addFieldsDefinedInSettingsMetadata();
63 // @todo look at sharing the code below in the settings trait.
64 if ($this->includesReadOnlyFields
) {
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]);
68 // @todo - do we still like this redirect?
69 CRM_Core_Session
::singleton()->pushUserContext(CRM_Utils_System
::url('civicrm/admin', 'reset=1'));
78 'name' => ts('Cancel'),
84 * Process the form submission.
86 public function postProcess() {
87 $params = $this->controller
->exportValues($this->_name
);
89 $this->saveMetadataDefinedSettings($params);
91 catch (CiviCRM_API3_Exception
$e) {
92 CRM_Core_Session
::setStatus($e->getMessage(), ts('Save Failed'), 'error');