3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2018
35 * Base class for admin forms.
37 class CRM_Admin_Form
extends CRM_Core_Form
{
40 * The id of the object being edited / created
47 * The default values for form fields.
54 * The name of the BAO object for this form.
61 * Explicitly declare the form context.
63 public function getDefaultContext() {
70 public function preProcess() {
71 Civi
::resources()->addStyleFile('civicrm', 'css/admin.css');
72 Civi
::resources()->addScriptFile('civicrm', 'js/crm.admin.js');
74 $this->_id
= $this->get('id');
75 $this->_BAOName
= $this->get('BAOName');
76 $this->_values
= array();
77 if (isset($this->_id
)) {
78 $params = array('id' => $this->_id
);
79 // this is needed if the form is outside the CRM name space
80 $baoName = $this->_BAOName
;
81 $baoName::retrieve($params, $this->_values
);
86 * Set default values for the form. Note that in edit/view mode
87 * the default values are retrieved from the database
92 public function setDefaultValues() {
93 // Fetch defaults from the db
94 if (!empty($this->_id
) && empty($this->_values
) && CRM_Utils_Rule
::positiveInteger($this->_id
)) {
95 $this->_values
= array();
96 $params = array('id' => $this->_id
);
97 $baoName = $this->_BAOName
;
98 $baoName::retrieve($params, $this->_values
);
100 $defaults = $this->_values
;
102 // Allow defaults to be set from the url
103 if (empty($this->_id
) && $this->_action
& CRM_Core_Action
::ADD
) {
104 foreach ($_GET as $key => $val) {
105 if ($this->elementExists($key)) {
106 $defaults[$key] = $val;
111 if ($this->_action
== CRM_Core_Action
::DELETE
&&
112 isset($defaults['name'])
114 $this->assign('delName', $defaults['name']);
117 // its ok if there is no element called is_active
118 $defaults['is_active'] = ($this->_id
) ? CRM_Utils_Array
::value('is_active', $defaults) : 1;
119 if (!empty($defaults['parent_id'])) {
120 $this->assign('is_parent', TRUE);
126 * Add standard buttons.
128 public function buildQuickForm() {
129 if ($this->_action
& CRM_Core_Action
::VIEW ||
$this->_action
& CRM_Core_Action
::PREVIEW
) {
130 $this->addButtons(array(
133 'name' => ts('Done'),
140 $this->addButtons(array(
143 'name' => $this->_action
& CRM_Core_Action
::DELETE ?
ts('Delete') : ts('Save'),
148 'name' => ts('Cancel'),