Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uw_cfg_common
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor 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
WCMS
uw_cfg_common
Commits
5e6b633b
Commit
5e6b633b
authored
4 years ago
by
Eric Bremner
Committed by
Igor Biki
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
ISTWCMS-4199: adding functions for getting menus to the uwService
parent
05abfe23
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!17
Feature/istwcms 4199 ebremner menu items count
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Service/UWService.php
+52
-11
52 additions, 11 deletions
src/Service/UWService.php
src/Service/UWServiceInterface.php
+34
-9
34 additions, 9 deletions
src/Service/UWServiceInterface.php
with
86 additions
and
20 deletions
src/Service/UWService.php
+
52
−
11
View file @
5e6b633b
...
@@ -271,24 +271,26 @@ class UWService implements UWServiceInterface {
...
@@ -271,24 +271,26 @@ class UWService implements UWServiceInterface {
/**
/**
* {@inheritDoc}
* {@inheritDoc}
*/
*/
public
function
getUw
Menu
(
string
$menu_name
=
'main'
):
array
{
public
function
uwGet
Menu
(
string
$menu_name
=
'main'
,
$include_parent_in_count
=
FALSE
):
array
{
// Get the main menu from the simplify menu module.
// Get the main menu from the simplify menu module.
$
main_
menu
=
$this
->
simplifyMenu
->
getMenuTree
(
'main'
);
$menu
=
$this
->
simplifyMenu
->
getMenuTree
(
$menu_name
);
// Set it to the menu_tree which is done by simplify menu.
// Set it to the menu_tree which is done by simplify menu.
$main_menu
=
$main_menu
[
'menu_tree'
];
$menu
=
$menu
[
'menu_tree'
];
$menu_items_count
=
0
;
// Add the count of the menu items.
// Add the count of the menu items.
$this
->
uw
Coun
tMenuItems
(
$m
ain_menu
);
$menu
=
$this
->
uw
Se
tMenuItems
(
$m
enu
,
$include_parent_in_count
);
return
$
main_
menu
;
return
$menu
;
}
}
/**
/**
* {@inheritDoc}
* {@inheritDoc}
*/
*/
public
function
uw
Coun
tMenuItems
(
&
$menus
)
:
void
{
public
function
uw
Se
tMenuItems
(
$menus
,
$include_parent_in_count
=
FALSE
):
array
{
// Step through the menu and do a few things:
// Step through the menu and do a few things:
// (a) Remove the Home link (this will be a house icon)
// (a) Remove the Home link (this will be a house icon)
...
@@ -307,26 +309,65 @@ class UWService implements UWServiceInterface {
...
@@ -307,26 +309,65 @@ class UWService implements UWServiceInterface {
else
{
else
{
// Set the menu_item_count, initially to 0.
// Set the menu_item_count, initially to 0.
$menu_item_count
=
0
;
$menu_item
s
_count
=
0
;
// If there is a submenu, recursivley call the count function.
// If there is a submenu, recursivley call the count function.
if
(
isset
(
$menu
[
'submenu'
])
&&
count
(
$menu
[
'submenu'
])
>
0
)
{
if
(
isset
(
$menu
[
'submenu'
])
&&
count
(
$menu
[
'submenu'
])
>
0
)
{
// Call the count function recursively till we have the number of
// Call the count function recursively till we have the number of
// menu items.
// menu items.
_uw_fdsu_theme_resp_c
ount
_m
enu
_i
tems
(
$menu
,
$menu_item_count
);
$this
->
uwC
ount
M
enu
I
tems
(
$menu
[
'submenu'
]
,
$menu_item
s
_count
);
// Set the menu items count.
// Set the menu items count.
$main_menu
[
$index
][
'menu_items_count'
]
=
$menu_item_count
+
1
;
// If we need to include the parent in the count, for example the
// main menu will print the parent inside the tray, then we increment
// the menu items count by 1.
if
(
$include_parent_in_count
)
{
$menu_items_count
++
;
}
// Set the menu items count in the menu.
$menus
[
$index
][
'menu_items_count'
]
=
$menu_items_count
;
}
// If there are no submenus, the count is 0, there will be no tray.
}
// If there are no submenus, the count is 0, there will be no tray.
else
{
else
{
// Set the number of items count, which is 0.
// Set the number of items count, which is 0.
$
main_
menu
[
$index
][
'menu_items_count'
]
=
$menu_item_count
;
$menu
s
[
$index
][
'menu_items_count'
]
=
$menu_item
s
_count
;
}
}
}
}
}
}
return
$menus
;
}
}
/**
* {@inheritDoc}
*/
public
function
uwCountMenuItems
(
$menus
,
&
$menu_items_count
)
:
void
{
// Step through the menus and check for submenus and count.
foreach
(
$menus
as
$index
=>
$menu
)
{
// If there is a submenu, recursivley call the count function.
if
(
isset
(
$menu
[
'submenu'
])
&&
count
(
$menu
[
'submenu'
])
>
0
)
{
// Increment the menu items counter.
$menu_items_count
++
;
// Recursively check the submenu.
$this
->
uwCountMenuItems
(
$menu
[
'submenu'
],
$menu_items_count
);
}
// If there are no submenus, simple increment the menu items counter.
else
{
// Increment the menu items counter.
$menu_items_count
++
;
}
}
}
}
}
This diff is collapsed.
Click to expand it.
src/Service/UWServiceInterface.php
+
34
−
9
View file @
5e6b633b
...
@@ -87,17 +87,28 @@ interface UWServiceInterface {
...
@@ -87,17 +87,28 @@ interface UWServiceInterface {
* A function to get an array of menu.
* A function to get an array of menu.
*
*
* @param string $menu_name
* @param string $menu_name
* A boolean to state if we want content types that can have sidebars.
* A string to the machine name of the menu to get.
* @param $include_parent_in_count
* A boolean on whether to include the parent in the menu items count.
*
*
* @return array
* @return array
* An array of the menu.
* An array of the menu.
*/
*/
public
function
getUw
Menu
(
string
$menu_name
=
'main'
):
array
;
public
function
uwGet
Menu
(
string
$menu_name
=
'main'
,
$include_parent_in_count
=
false
):
array
;
/**
/**
* A recursive function to count the number of menu items.
* A function to setup the menu for UW display.
*
* This function will count of the number of menu items,
* and use a recursive function (uwCountMenuItems) to count
* the total number of menu items.
*
* The variable include_parent_in_count tells us if we need
* to add one to the total count of menu items. This is required
* for displaying some menus as the parent is also included
* in the displaying of the menu (i.e. the tray of the main and
* information for menus).
*
*
* This function will count of the number of menu items.
* For example, the menu structure will look like:
* For example, the menu structure will look like:
* Parent
* Parent
* Child #1
* Child #1
...
@@ -112,12 +123,26 @@ interface UWServiceInterface {
...
@@ -112,12 +123,26 @@ interface UWServiceInterface {
* Grandchild #3-3
* Grandchild #3-3
* Great grandchild #3-3-1
* Great grandchild #3-3-1
* So it should with the recursive function it will return 11.
* So it should with the recursive function it will return 11.
* If we include the parent the count will be 12.
*
* @param &$menus
* A reference to the array list of menu items.
* @param $include_parent_in_count
* A boolean on whether to include the parent in the menu items count.
*
* @return array
* An array of the updated menu items.
*/
public
function
uwSetMenuItems
(
$menus
,
$include_parent_in_count
=
false
):
array
;
/**
* A function to recursively count the number of menu items in the submenu.
*
*
* @param $menu
s
* @param $menu
*
The
array
list of menu items
.
*
An
array
that contains the submenu
.
* @param
&
$menu_items_count
* @param $menu_items_count
*
The
reference to the
number of items variable
.
*
A
reference to the
integer that is storing the number of menu items
.
*/
*/
public
function
uwCountMenuItems
(
&
$menus
)
:
void
;
public
function
uwCountMenuItems
(
array
$menu
,
int
&
$menu_items_count
):
void
;
}
}
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