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 * Base class for settings forms.
21 class CRM_Admin_Form_Preferences
extends CRM_Core_Form
{
23 use CRM_Admin_Form_SettingTrait
;
25 protected $_system = FALSE;
26 protected $_contactID = NULL;
27 public $_action = NULL;
29 protected $_params = NULL;
34 * @throws \CRM_Core_Exception
36 public function preProcess() {
37 // @todo - it's likely the only 'current' code in this function is the line
38 // $this->addFieldsDefinedInSettingsMetadata(); and this class is no different to CRM_Admin_Form_Setting
39 // in any meaningful way.
40 $this->_contactID
= CRM_Utils_Request
::retrieve('cid', 'Positive',
43 $this->_system
= CRM_Utils_Request
::retrieve('system', 'Boolean',
46 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String',
47 $this, FALSE, 'update'
51 if (CRM_Core_Permission
::check('administer CiviCRM')) {
52 $this->_contactID
= NULL;
55 throw new CRM_Core_Exception('You do not have permission to edit preferences');
59 if (!$this->_contactID
) {
60 $this->_contactID
= CRM_Core_Session
::getLoggedInContactID();
61 if (!$this->_contactID
) {
62 throw new CRM_Core_Exception('Could not retrieve contact id');
64 $this->set('cid', $this->_contactID
);
68 $this->addFieldsDefinedInSettingsMetadata();
69 CRM_Core_Session
::singleton()->pushUserContext(CRM_Utils_System
::url('civicrm/admin', 'reset=1'));
75 public function setDefaultValues() {
76 $this->_defaults
= [];
77 $this->setDefaultsForMetadataDefinedFields();
78 return $this->_defaults
;
82 * Build the form object.
84 public function buildQuickForm() {
85 parent
::buildQuickForm();
95 'name' => ts('Cancel'),
99 if ($this->_action
== CRM_Core_Action
::VIEW
) {
105 * Process the form submission.
107 public function postProcess() {
108 if ($this->_action
== CRM_Core_Action
::VIEW
) {
112 $this->_params
= $this->controller
->exportValues($this->_name
);
114 $this->postProcessCommon();
118 * Process the form submission.
120 public function postProcessCommon() {
122 $this->saveMetadataDefinedSettings($this->_params
);
123 $this->filterParamsSetByMetadata($this->_params
);
125 catch (CiviCRM_API3_Exception
$e) {
126 CRM_Core_Session
::setStatus($e->getMessage(), ts('Save Failed'), 'error');
129 // Update any settings stored in dynamic js
130 CRM_Core_Resources
::singleton()->resetCacheCode();
132 CRM_Core_Session
::setStatus(ts('Your changes have been saved.'), ts('Saved'), 'success');