Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
CiviCRM Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Development
CiviCRM Core
Commits
bddbea9a
Unverified
Commit
bddbea9a
authored
3 months ago
by
mattwire
Committed by
GitHub
3 months ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #31779 from colemanw/navMenu
Navigation - Get 'delete' link working
parents
36c16e83
a1f41c5f
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CRM/Admin/Form/Navigation.php
+24
-5
24 additions, 5 deletions
CRM/Admin/Form/Navigation.php
CRM/Core/BAO/Navigation.php
+22
-0
22 additions, 0 deletions
CRM/Core/BAO/Navigation.php
templates/CRM/Admin/Form/Navigation.tpl
+69
-45
69 additions, 45 deletions
templates/CRM/Admin/Form/Navigation.tpl
with
115 additions
and
50 deletions
CRM/Admin/Form/Navigation.php
+
24
−
5
View file @
bddbea9a
...
...
@@ -41,13 +41,16 @@ class CRM_Admin_Form_Navigation extends CRM_Admin_Form {
public
function
buildQuickForm
()
{
parent
::
buildQuickForm
();
if
(
$this
->
_action
&
CRM_Core_Action
::
DELETE
)
{
return
;
}
if
(
isset
(
$this
->
_id
))
{
$params
=
[
'id'
=>
$this
->
_id
];
CRM_Core_BAO_Navigation
::
retrieve
(
$params
,
$this
->
_defaults
);
$navDao
=
CRM_Core_BAO_Navigation
::
retrieve
(
$params
,
$this
->
_defaults
);
}
if
(
$this
->
_action
&
CRM_Core_Action
::
DELETE
)
{
$childCount
=
CRM_Core_BAO_Navigation
::
getChildCount
(
$this
->
_id
);
$this
->
assign
(
'label'
,
$navDao
->
label
?:
$navDao
->
url
);
$this
->
assign
(
'childCount'
,
$childCount
);
return
;
}
$this
->
applyFilter
(
'__ALL__'
,
'trim'
);
...
...
@@ -106,6 +109,11 @@ class CRM_Admin_Form_Navigation extends CRM_Admin_Form {
*/
public
function
setDefaultValues
()
{
$defaults
=
parent
::
setDefaultValues
();
if
(
$this
->
_action
&
CRM_Core_Action
::
DELETE
)
{
return
$defaults
;
}
if
(
isset
(
$this
->
_id
))
{
//Take parent id in object variable to calculate the menu
//weight if menu parent id changed
...
...
@@ -132,6 +140,17 @@ class CRM_Admin_Form_Navigation extends CRM_Admin_Form {
// get the submitted form values.
$params
=
$this
->
controller
->
exportValues
(
$this
->
_name
);
if
(
$this
->
_action
&
CRM_Core_Action
::
DELETE
)
{
CRM_Core_BAO_Navigation
::
deleteRecords
([[
'id'
=>
$this
->
_id
]]);
$childCount
=
$this
->
getTemplateVars
(
'childCount'
);
$msg
=
ts
(
'One menu item permanently deleted.'
,
[
'plural'
=>
'%count menu items permanently deleted.'
,
'count'
=>
$childCount
+
1
,
]);
CRM_Core_Session
::
setStatus
(
$msg
,
ts
(
'Deleted'
),
'success'
);
return
;
}
if
(
isset
(
$this
->
_id
))
{
$params
[
'id'
]
=
$this
->
_id
;
$params
[
'current_parent_id'
]
=
$this
->
_currentParentID
;
...
...
This diff is collapsed.
Click to expand it.
CRM/Core/BAO/Navigation.php
+
22
−
0
View file @
bddbea9a
...
...
@@ -875,6 +875,28 @@ ORDER BY weight";
}
}
/**
* Count all nested child items (including sub-children and sub-sub-children, etc).
*
* @param int $id
* The ID of the parent item.
*
* @return int
* The total number of children.
*/
public
static
function
getChildCount
(
int
$id
):
int
{
$childCount
=
0
;
$parentIds
=
[
$id
];
while
(
$parentIds
)
{
$parentIds
=
\Civi\Api4\Navigation
::
get
(
FALSE
)
->
addWhere
(
'parent_id'
,
'IN'
,
$parentIds
)
->
addSelect
(
'id'
)
->
execute
()
->
column
(
'id'
);
$childCount
+=
count
(
$parentIds
);
}
return
$childCount
;
}
/**
* @param array $menu
*/
...
...
This diff is collapsed.
Click to expand it.
templates/CRM/Admin/Form/Navigation.tpl
+
69
−
45
View file @
bddbea9a
...
...
@@ -7,49 +7,73 @@
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*}
{* Template for adding/editing a CiviCRM Navigation Menu Item *}
<div
class=
"crm-block crm-form-block crm-navigation-form-block"
>
<table
class=
"form-layout-compressed"
>
<tr
class=
"crm-navigation-form-block-label"
>
<td
class=
"label"
>
{
$form.label.label
}
</td><td>
{
$form.label.html
}
</td>
</tr>
<tr
class=
"crm-navigation-form-block-url"
>
<td
class=
"label"
>
{
$form.url.label
}
{
help
id
=
"id-menu_url"
file
=
"CRM/Admin/Form/Navigation.hlp"
}
</td>
<td>
{
$form.url.html
}
</td>
</tr>
<tr
class=
"crm-navigation-form-block-icon"
>
<td
class=
"label"
>
{
$form.icon.label
}
{
help
id
=
"id-menu_icon"
file
=
"CRM/Admin/Form/Navigation.hlp"
}
</td>
<td>
{
$form.icon.html
}
</td>
</tr>
{
if
!
empty
(
$form.parent_id.html
)
}
<tr
class=
"crm-navigation-form-block-parent_id"
>
<td
class=
"label"
>
{
$form.parent_id.label
}
{
help
id
=
"id-parent"
file
=
"CRM/Admin/Form/Navigation.hlp"
}
</td>
<td>
{
$form.parent_id.html
}
</td>
{* Template for CiviCRM Navigation Menu Item form *}
{
if
$action
eq
8
}
{* Delete *}
<div
class=
"messages status no-popup"
>
{
icon
icon
=
"fa-info-circle"
}{/
icon
}
{
ts
1
=
$label
}
Menu item "%1" will be permanently deleted for all users of this site.
{/
ts
}
</div>
{
if
$childCount
}
<div
class=
"messages crm-error no-popup"
>
{
icon
icon
=
"fa-exclamation-triangle"
}{/
icon
}
{
if
$childCount
>
1
}
{
ts
1
=
$childCount
}
%1 sub-menu items will also be deleted.
{/
ts
}
{
else
}
{
ts
}
One sub-menu item will also be deleted.
{/
ts
}
{/
if
}
</div>
{/
if
}
<p>
{
ts
}
Do you want to continue?
{/
ts
}
</p>
<div
class=
"form-item"
>
{
include
file
=
"CRM/common/formButtons.tpl"
}
</div>
{
else
}
{* Add/Edit *}
<div
class=
"crm-block crm-form-block crm-navigation-form-block"
>
<table
class=
"form-layout-compressed"
>
<tr
class=
"crm-navigation-form-block-label"
>
<td
class=
"label"
>
{
$form.label.label
}
</td><td>
{
$form.label.html
}
</td>
</tr>
{/
if
}
<tr
class=
"crm-navigation-form-block-has_separator"
>
<td
class=
"label"
>
{
$form.has_separator.label
}
{
help
id
=
"id-has_separator"
file
=
"CRM/Admin/Form/Navigation.hlp"
}
</td>
<td>
{
$form.has_separator.html
}
</td>
</tr>
<tr
class=
"crm-navigation-form-block-permission"
>
<td
class=
"label"
>
{
$form.permission.label
}
{
help
id
=
"id-menu_permission"
file
=
"CRM/Admin/Form/Navigation.hlp"
}
</td>
<td>
{
$form.permission.html
}
<span
class=
"permission_operator_wrapper"
>
{
$form.permission_operator.html
}
{
help
id
=
"id-permission_operator"
file
=
"CRM/Admin/Form/Navigation.hlp"
}
</span></td>
</tr>
<tr
class=
"crm-navigation-form-block-is_active"
>
<td
class=
"label"
>
{
$form.is_active.label
}
</td><td>
{
$form.is_active.html
}
</td>
</tr>
</table>
<div
class=
"crm-submit-buttons"
>
{
include
file
=
"CRM/common/formButtons.tpl"
location
=
"bottom"
}
</div>
</div>
{
literal
}
<script
type=
"text/javascript"
>
CRM
.
$
(
function
(
$
)
{
var
$form
=
$
(
'
form.
{/
literal
}{
$form.formClass
}{
literal
}
'
);
$
(
'
input[name=permission]
'
,
$form
)
.
on
(
'
change
'
,
function
()
{
$
(
'
span.permission_operator_wrapper
'
).
toggle
(
CRM
.
_
.
includes
(
$
(
this
).
val
(),
'
,
'
));
})
.
change
();
});
</script>
{/
literal
}
<tr
class=
"crm-navigation-form-block-url"
>
<td
class=
"label"
>
{
$form.url.label
}
{
help
id
=
"id-menu_url"
file
=
"CRM/Admin/Form/Navigation.hlp"
}
</td>
<td>
{
$form.url.html
}
</td>
</tr>
<tr
class=
"crm-navigation-form-block-icon"
>
<td
class=
"label"
>
{
$form.icon.label
}
{
help
id
=
"id-menu_icon"
file
=
"CRM/Admin/Form/Navigation.hlp"
}
</td>
<td>
{
$form.icon.html
}
</td>
</tr>
{
if
!
empty
(
$form.parent_id.html
)
}
<tr
class=
"crm-navigation-form-block-parent_id"
>
<td
class=
"label"
>
{
$form.parent_id.label
}
{
help
id
=
"id-parent"
file
=
"CRM/Admin/Form/Navigation.hlp"
}
</td>
<td>
{
$form.parent_id.html
}
</td>
</tr>
{/
if
}
<tr
class=
"crm-navigation-form-block-has_separator"
>
<td
class=
"label"
>
{
$form.has_separator.label
}
{
help
id
=
"id-has_separator"
file
=
"CRM/Admin/Form/Navigation.hlp"
}
</td>
<td>
{
$form.has_separator.html
}
</td>
</tr>
<tr
class=
"crm-navigation-form-block-permission"
>
<td
class=
"label"
>
{
$form.permission.label
}
{
help
id
=
"id-menu_permission"
file
=
"CRM/Admin/Form/Navigation.hlp"
}
</td>
<td>
{
$form.permission.html
}
<span
class=
"permission_operator_wrapper"
>
{
$form.permission_operator.html
}
{
help
id
=
"id-permission_operator"
file
=
"CRM/Admin/Form/Navigation.hlp"
}
</span></td>
</tr>
<tr
class=
"crm-navigation-form-block-is_active"
>
<td
class=
"label"
>
{
$form.is_active.label
}
</td><td>
{
$form.is_active.html
}
</td>
</tr>
</table>
<div
class=
"crm-submit-buttons"
>
{
include
file
=
"CRM/common/formButtons.tpl"
location
=
"bottom"
}
</div>
</div>
{
literal
}
<script
type=
"text/javascript"
>
CRM
.
$
(
function
(
$
)
{
var
$form
=
$
(
'
form.
{/
literal
}{
$form.formClass
}{
literal
}
'
);
// Show AND/OR selector only if multiple permissions are selected
$
(
'
input[name=permission]
'
,
$form
)
.
on
(
'
change
'
,
function
()
{
$
(
'
span.permission_operator_wrapper
'
).
toggle
(
$
(
this
).
val
().
includes
(
'
,
'
));
})
.
change
();
});
</script>
{/
literal
}
{/
if
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment