Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Developer Documentation
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
brienne
Developer Documentation
Commits
871b9334
Commit
871b9334
authored
8 years ago
by
Andie Hunt
Browse files
Options
Downloads
Patches
Plain Diff
hook_civicrm_navigationMenu: fixed formatting
parent
fe861aa8
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
docs/hooks/hook_civicrm_navigationMenu.md
+102
-99
102 additions, 99 deletions
docs/hooks/hook_civicrm_navigationMenu.md
with
102 additions
and
99 deletions
docs/hooks/hook_civicrm_navigationMenu.md
+
102
−
99
View file @
871b9334
...
...
@@ -8,119 +8,122 @@ for any parent.
## Definition
hook_civicrm_navigationMenu( &$params )
```
php
hook_civicrm_navigationMenu
(
&
$params
)
```
## Parameters
-
$params the navigation menu array
-
`
$params
`
the navigation menu array
Attributes of the menu :
Attributes of the menu :
1.
label
:
N
avigation
T
itle
- string `
label
`
:
n
avigation
t
itle
2. N
ame
:
I
nternal
N
ame
- string `n
ame
`
:
i
nternal
n
ame
3.
url
:
url
in case of custom navigation link
- string `
url
`
:
URL
in case of custom navigation link
4.
permission
: comma separated
P
ermissions for menu item
- string `
permission
`
: comma separated
p
ermissions for menu item
5.
operator
:
P
ermission
O
perator (
AND
/
OR)
- string `
operator
`
:
p
ermission
o
perator (
`
AND
` or `
OR
`
)
6. seperator : 0 or null = No Separator, 1 = Separator after this
menu item, 2 = Separator before this menu item.
- int `separator`: whether to insert a Separator
7. parentID : Parent navigation item, used for grouping
- `0` or `NULL` = No Separator,
- `1` = Separator after this menu item,
- `2` = Separator before this menu item.
8. nav
ID
:
ID of the menu
- int `parent
ID
`
:
parent navigation item, used for grouping
9. active : is active ?
- int`navID`: ID of the menu
## Exampl
e
- bool `active`: whether the item is activ
e
function _getMenuKeyMax($menuArray) {
$max = array(max(array_keys($menuArray)));
foreach($menuArray as $v) {
if (!empty($v['child'])) {
$max[] = _getMenuKeyMax($v['child']);
}
}
return max($max);
}
function civicrm_civicrm_navigationMenu( &$params ) {
// Get the maximum key of $params
$maxKey = getMenuKeyMax($params);
$params[$maxKey+1] = array (
'attributes' => array (
'label' => 'Custom Menu Entry',
'name' => 'Custom Menu Entry',
'url' => null,
'permission' => null,
'operator' => null,
'separator' => null,
'parentID' => null,
'navID' => $maxKey+1,
'active' => 1
),
'child' => array (
'1' => array (
'attributes' => array (
'label' => 'Custom Child Menu',
'name' => 'Custom Child Menu',
'url' => 'http://www.testlink.com',
'permission' => 'access CiviContribute',
'operator' => null,
'separator' => 1,
'parentID' => $maxKey+1,
'navID' => 1,
'active' => 1
),
'child' => null
) ) );
}
## Examples
## Example: to add your menu item to an existing menu
function donortrends_civicrm_navigationMenu(&$params) {
// Check that our item doesn't already exist
$menu_item_search = array('url' => 'civicrm/trends');
$menu_items = array();
CRM_Core_BAO_Navigation::retrieve($menu_item_search, $menu_items);
if ( ! empty($menu_items) ) {
return;
}
$navId = CRM_Core_DAO::singleValueQuery("SELECT max(id) FROM civicrm_navigation");
if (is_integer($navId)) {
$navId++;
}
// Find the Report menu
$reportID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Navigation', 'Reports', 'id', 'name');
$params[$reportID]['child'][$navId] = array (
'attributes' => array (
'label' => ts('Donor Trends',array('domain' => 'org.eff.donortrends')),
'name' => 'Donor Trends',
'url' => 'civicrm/trends',
'permission' => 'access CiviReport,access CiviContribute',
'operator' => 'OR',
'separator' => 1,
'parentID' => $reportID,
'navID' => $navId,
'active' => 1
)
);
```
php
function
_getMenuKeyMax
(
$menuArray
)
{
$max
=
array
(
max
(
array_keys
(
$menuArray
)));
foreach
(
$menuArray
as
$v
)
{
if
(
!
empty
(
$v
[
'child'
]))
{
$max
[]
=
_getMenuKeyMax
(
$v
[
'child'
]);
}
Both of these examples were a bit dangerous - they each provide a way to
find the next available id, but the first one fails because it's not
finding the child menu id numbers, and the second one fails because it's
not taking into account the id's that other extensions might have added.
I've just added a little recursive function to the first one to fix it.
\ No newline at end of file
}
return
max
(
$max
);
}
function
civicrm_civicrm_navigationMenu
(
&
$params
)
{
// Get the maximum key of $params
$maxKey
=
getMenuKeyMax
(
$params
);
$params
[
$maxKey
+
1
]
=
array
(
'attributes'
=>
array
(
'label'
=>
'Custom Menu Entry'
,
'name'
=>
'Custom Menu Entry'
,
'url'
=>
null
,
'permission'
=>
null
,
'operator'
=>
null
,
'separator'
=>
null
,
'parentID'
=>
null
,
'navID'
=>
$maxKey
+
1
,
'active'
=>
1
),
'child'
=>
array
(
'1'
=>
array
(
'attributes'
=>
array
(
'label'
=>
'Custom Child Menu'
,
'name'
=>
'Custom Child Menu'
,
'url'
=>
'http://www.testlink.com'
,
'permission'
=>
'access CiviContribute'
,
'operator'
=>
NULL
,
'separator'
=>
1
,
'parentID'
=>
$maxKey
+
1
,
'navID'
=>
1
,
'active'
=>
1
),
'child'
=>
NULL
,
),
),
);
}
```
To add your menu item to an existing menu
```
php
function
donortrends_civicrm_navigationMenu
(
&
$params
)
{
// Check that our item doesn't already exist
$menu_item_search
=
array
(
'url'
=>
'civicrm/trends'
);
$menu_items
=
array
();
CRM_Core_BAO_Navigation
::
retrieve
(
$menu_item_search
,
$menu_items
);
if
(
!
empty
(
$menu_items
)
)
{
return
;
}
$navId
=
CRM_Core_DAO
::
singleValueQuery
(
"SELECT max(id) FROM civicrm_navigation"
);
if
(
is_integer
(
$navId
))
{
$navId
++
;
}
// Find the Report menu
$reportID
=
CRM_Core_DAO
::
getFieldValue
(
'CRM_Core_DAO_Navigation'
,
'Reports'
,
'id'
,
'name'
);
$params
[
$reportID
][
'child'
][
$navId
]
=
array
(
'attributes'
=>
array
(
'label'
=>
ts
(
'Donor Trends'
,
array
(
'domain'
=>
'org.eff.donortrends'
)),
'name'
=>
'Donor Trends'
,
'url'
=>
'civicrm/trends'
,
'permission'
=>
'access CiviReport,access CiviContribute'
,
'operator'
=>
'OR'
,
'separator'
=>
1
,
'parentID'
=>
$reportID
,
'navID'
=>
$navId
,
'active'
=>
1
),
);
}
```
The second example is a bit dangerous because it isn't taking into account the IDs that other extensions might have added.
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