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 admin forms.
21 class CRM_Admin_Form
extends CRM_Core_Form
{
24 * The id of the object being edited / created
31 * The default values for form fields.
38 * The name of the BAO object for this form.
45 * Explicitly declare the form context.
47 public function getDefaultContext() {
54 public function preProcess() {
55 Civi
::resources()->addStyleFile('civicrm', 'css/admin.css');
56 Civi
::resources()->addScriptFile('civicrm', 'js/jquery/jquery.crmIconPicker.js');
58 $this->_id
= $this->get('id');
59 $this->_BAOName
= $this->get('BAOName');
61 if (isset($this->_id
)) {
62 $params = ['id' => $this->_id
];
63 // this is needed if the form is outside the CRM name space
64 $baoName = $this->_BAOName
;
65 $baoName::retrieve($params, $this->_values
);
70 * Set default values for the form. Note that in edit/view mode
71 * the default values are retrieved from the database
76 public function setDefaultValues() {
77 // Fetch defaults from the db
78 if (!empty($this->_id
) && empty($this->_values
) && CRM_Utils_Rule
::positiveInteger($this->_id
)) {
80 $params = ['id' => $this->_id
];
81 $baoName = $this->_BAOName
;
82 $baoName::retrieve($params, $this->_values
);
84 $defaults = $this->_values
;
86 // Allow defaults to be set from the url
87 if (empty($this->_id
) && $this->_action
& CRM_Core_Action
::ADD
) {
88 foreach ($_GET as $key => $val) {
89 if ($this->elementExists($key)) {
90 $defaults[$key] = $val;
95 if ($this->_action
== CRM_Core_Action
::DELETE
&&
96 isset($defaults['name'])
98 $this->assign('delName', $defaults['name']);
101 // its ok if there is no element called is_active
102 $defaults['is_active'] = ($this->_id
) ? CRM_Utils_Array
::value('is_active', $defaults) : 1;
103 if (!empty($defaults['parent_id'])) {
104 $this->assign('is_parent', TRUE);
110 * Add standard buttons.
112 public function buildQuickForm() {
113 if ($this->_action
& CRM_Core_Action
::VIEW ||
$this->_action
& CRM_Core_Action
::PREVIEW
) {
117 'name' => ts('Done'),
126 'name' => $this->_action
& CRM_Core_Action
::DELETE ?
ts('Delete') : ts('Save'),
131 'name' => ts('Cancel'),