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 * This class generates form components for Navigation.
21 class CRM_Admin_Form_Navigation
extends CRM_Admin_Form
{
24 * The parent id of the navigation menu.
27 protected $_currentParentID = NULL;
30 * Build the form object.
32 public function buildQuickForm() {
33 parent
::buildQuickForm();
35 $this->setPageTitle(ts('Menu Item'));
37 if ($this->_action
& CRM_Core_Action
::DELETE
) {
41 if (isset($this->_id
)) {
42 $params = ['id' => $this->_id
];
43 CRM_Core_BAO_Navigation
::retrieve($params, $this->_defaults
);
46 $this->applyFilter('__ALL__', 'trim');
50 CRM_Core_DAO
::getAttribute('CRM_Core_DAO_Navigation', 'label'),
54 $this->add('text', 'url', ts('Url'), CRM_Core_DAO
::getAttribute('CRM_Core_DAO_Navigation', 'url'));
56 $this->add('text', 'icon', ts('Icon'), ['class' => 'crm-icon-picker', 'title' => ts('Choose Icon'), 'allowClear' => TRUE]);
59 foreach (CRM_Core_Permission
::basicPermissions(TRUE, TRUE) as $id => $vals) {
60 $permissions[] = ['id' => $id, 'text' => $vals[0], 'description' => (array) CRM_Utils_Array
::value(1, $vals)];
62 $this->add('select2', 'permission', ts('Permission'), $permissions, FALSE,
63 ['placeholder' => ts('Unrestricted'), 'class' => 'huge', 'multiple' => TRUE]
66 $operators = ['AND' => ts('AND'), 'OR' => ts('OR')];
67 $this->add('select', 'permission_operator', NULL, $operators);
69 //make separator location configurable
70 $separator = CRM_Core_SelectValues
::navigationMenuSeparator();
71 $this->add('select', 'has_separator', ts('Separator'), $separator);
73 $active = $this->add('advcheckbox', 'is_active', ts('Enabled'));
75 if (CRM_Utils_Array
::value('name', $this->_defaults
) == 'Home') {
79 $parentMenu = CRM_Core_BAO_Navigation
::getNavigationList();
81 if (isset($this->_id
)) {
82 unset($parentMenu[$this->_id
]);
86 $homeMenuId = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_Navigation', 'Home', 'id', 'name');
87 unset($parentMenu[$homeMenuId]);
89 $this->add('select', 'parent_id', ts('Parent'), ['' => ts('Top level')] +
$parentMenu, FALSE, ['class' => 'crm-select2']);
96 public function setDefaultValues() {
97 $defaults = parent
::setDefaultValues();
98 if (isset($this->_id
)) {
99 //Take parent id in object variable to calculate the menu
100 //weight if menu parent id changed
101 $this->_currentParentID
= $this->_defaults
['parent_id'] ??
NULL;
104 $defaults['permission'] = "access CiviCRM";
107 // its ok if there is no element called is_active
108 $defaults['is_active'] = ($this->_id
) ?
$this->_defaults
['is_active'] : 1;
110 if (!empty($defaults['icon'])) {
111 $defaults['icon'] = trim(str_replace('crm-i', '', $defaults['icon']));
118 * Process the form submission.
120 public function postProcess() {
121 // get the submitted form values.
122 $params = $this->controller
->exportValues($this->_name
);
124 if (isset($this->_id
)) {
125 $params['id'] = $this->_id
;
126 $params['current_parent_id'] = $this->_currentParentID
;
129 if (!empty($params['icon'])) {
130 $params['icon'] = 'crm-i ' . $params['icon'];
133 $navigation = CRM_Core_BAO_Navigation
::add($params);
135 // also reset navigation
136 CRM_Core_BAO_Navigation
::resetNavigation();
138 CRM_Core_Session
::setStatus(ts('Menu \'%1\' has been saved.',
139 [1 => $navigation->label
]
140 ), ts('Saved'), 'success');