3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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-2019
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.
43 protected $_currentParentID = NULL;
46 * Build the form object.
48 public function buildQuickForm() {
49 parent
::buildQuickForm();
51 $this->setPageTitle(ts('Menu Item'));
53 if ($this->_action
& CRM_Core_Action
::DELETE
) {
57 if (isset($this->_id
)) {
58 $params = ['id' => $this->_id
];
59 CRM_Core_BAO_Navigation
::retrieve($params, $this->_defaults
);
62 $this->applyFilter('__ALL__', 'trim');
66 CRM_Core_DAO
::getAttribute('CRM_Core_DAO_Navigation', 'label'),
70 $this->add('text', 'url', ts('Url'), CRM_Core_DAO
::getAttribute('CRM_Core_DAO_Navigation', 'url'));
72 $this->add('text', 'icon', ts('Icon'), ['class' => 'crm-icon-picker', 'title' => ts('Choose Icon'), 'allowClear' => TRUE]);
75 foreach (CRM_Core_Permission
::basicPermissions(TRUE, TRUE) as $id => $vals) {
76 $permissions[] = ['id' => $id, 'text' => $vals[0], 'description' => (array) CRM_Utils_Array
::value(1, $vals)];
78 $this->add('select2', 'permission', ts('Permission'), $permissions, FALSE,
79 ['placeholder' => ts('Unrestricted'), 'class' => 'huge', 'multiple' => TRUE]
82 $operators = ['AND' => ts('AND'), 'OR' => ts('OR')];
83 $this->add('select', 'permission_operator', NULL, $operators);
85 //make separator location configurable
86 $separator = [ts('None'), ts('After menu element'), ts('Before menu element')];
87 $this->add('select', 'has_separator', ts('Separator'), $separator);
89 $active = $this->add('advcheckbox', 'is_active', ts('Enabled'));
91 if (CRM_Utils_Array
::value('name', $this->_defaults
) == 'Home') {
95 $parentMenu = CRM_Core_BAO_Navigation
::getNavigationList();
97 if (isset($this->_id
)) {
98 unset($parentMenu[$this->_id
]);
102 $homeMenuId = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_Navigation', 'Home', 'id', 'name');
103 unset($parentMenu[$homeMenuId]);
105 $this->add('select', 'parent_id', ts('Parent'), ['' => ts('Top level')] +
$parentMenu, FALSE, ['class' => 'crm-select2']);
112 public function setDefaultValues() {
113 $defaults = parent
::setDefaultValues();
114 if (isset($this->_id
)) {
115 //Take parent id in object variable to calculate the menu
116 //weight if menu parent id changed
117 $this->_currentParentID
= CRM_Utils_Array
::value('parent_id', $this->_defaults
);
120 $defaults['permission'] = "access CiviCRM";
123 // its ok if there is no element called is_active
124 $defaults['is_active'] = ($this->_id
) ?
$this->_defaults
['is_active'] : 1;
126 if (!empty($defaults['icon'])) {
127 $defaults['icon'] = trim(str_replace('crm-i', '', $defaults['icon']));
134 * Process the form submission.
136 public function postProcess() {
137 // get the submitted form values.
138 $params = $this->controller
->exportValues($this->_name
);
140 if (isset($this->_id
)) {
141 $params['id'] = $this->_id
;
142 $params['current_parent_id'] = $this->_currentParentID
;
145 if (!empty($params['icon'])) {
146 $params['icon'] = 'crm-i ' . $params['icon'];
149 $navigation = CRM_Core_BAO_Navigation
::add($params);
151 // also reset navigation
152 CRM_Core_BAO_Navigation
::resetNavigation();
154 CRM_Core_Session
::setStatus(ts('Menu \'%1\' has been saved.',
155 [1 => $navigation->label
]
156 ), ts('Saved'), 'success');