3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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-2016
35 * This class generates form components for Navigation.
37 class CRM_Admin_Form_Navigation
extends CRM_Admin_Form
{
40 * The parent id of the navigation menu.
42 protected $_currentParentID = NULL;
45 * Build the form object.
47 public function buildQuickForm() {
48 parent
::buildQuickForm();
50 $this->setPageTitle(ts('Menu Item'));
52 if ($this->_action
& CRM_Core_Action
::DELETE
) {
56 if (isset($this->_id
)) {
57 $params = array('id' => $this->_id
);
58 CRM_Core_BAO_Navigation
::retrieve($params, $this->_defaults
);
61 $this->applyFilter('__ALL__', 'trim');
65 CRM_Core_DAO
::getAttribute('CRM_Core_DAO_Navigation', 'label'),
69 $this->add('text', 'url', ts('Url'), CRM_Core_DAO
::getAttribute('CRM_Core_DAO_Navigation', 'url'));
70 $permissions = array();
71 foreach (CRM_Core_Permission
::basicPermissions(TRUE, TRUE) as $id => $vals) {
72 $permissions[] = array('id' => $id, 'label' => $vals[0], 'description' => (array) CRM_Utils_Array
::value(1, $vals));
74 $this->add('text', 'permission', ts('Permission'),
75 array('placeholder' => ts('Unrestricted'), 'class' => 'huge', 'data-select-params' => json_encode(array('data' => array('results' => $permissions, 'text' => 'label'))))
78 $operators = array('AND' => ts('AND'), 'OR' => ts('OR'));
79 $this->add('select', 'permission_operator', NULL, $operators);
81 //make separator location configurable
82 $separator = array(ts('None'), ts('After menu element'), ts('Before menu element'));
83 $this->add('select', 'has_separator', ts('Separator'), $separator);
85 $active = $this->add('advcheckbox', 'is_active', ts('Enabled'));
87 if (CRM_Utils_Array
::value('name', $this->_defaults
) == 'Home') {
91 $parentMenu = CRM_Core_BAO_Navigation
::getNavigationList();
93 if (isset($this->_id
)) {
94 unset($parentMenu[$this->_id
]);
98 $homeMenuId = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_Navigation', 'Home', 'id', 'name');
99 unset($parentMenu[$homeMenuId]);
101 $this->add('select', 'parent_id', ts('Parent'), array('' => ts('Top level')) +
$parentMenu, FALSE, array('class' => 'crm-select2'));
108 public function setDefaultValues() {
109 $defaults = $this->_defaults
;
110 if (isset($this->_id
)) {
111 //Take parent id in object variable to calculate the menu
112 //weight if menu parent id changed
113 $this->_currentParentID
= CRM_Utils_Array
::value('parent_id', $this->_defaults
);
116 $defaults['permission'] = "access CiviCRM";
119 // its ok if there is no element called is_active
120 $defaults['is_active'] = ($this->_id
) ?
$this->_defaults
['is_active'] : 1;
126 * Process the form submission.
128 public function postProcess() {
129 // get the submitted form values.
130 $params = $this->controller
->exportValues($this->_name
);
132 if (isset($this->_id
)) {
133 $params['id'] = $this->_id
;
134 $params['current_parent_id'] = $this->_currentParentID
;
137 $navigation = CRM_Core_BAO_Navigation
::add($params);
139 // also reset navigation
140 CRM_Core_BAO_Navigation
::resetNavigation();
142 CRM_Core_Session
::setStatus(ts('Menu \'%1\' has been saved.',
143 array(1 => $navigation->label
)
144 ), ts('Saved'), 'success');