Skip to content
Snippets Groups Projects
Commit 1839baef authored by Eric Bremner's avatar Eric Bremner Committed by Igor Biki
Browse files

ISTWCMS-4199: coding standards

parent 5e6b633b
No related branches found
No related tags found
1 merge request!17Feature/istwcms 4199 ebremner menu items count
......@@ -32,7 +32,7 @@ class UWService implements UWServiceInterface {
private $database;
/**
* Simplify_menu menu.
* Simplify_menu menu items.
*
* @var \Drupal\simplify_menu\MenuItems
*/
......@@ -45,6 +45,8 @@ class UWService implements UWServiceInterface {
* Entity Type Manager from core.
* @param \Drupal\Core\Database\Connection $database
* The database entity.
* @param \Drupal\simplify_menu\MenuItems $simplifyMenu
* The simplify_menu menu items.
*/
public function __construct(EntityTypeManagerInterface $entityTypeManager, Connection $database, MenuItems $simplifyMenu) {
$this->entityTypeManager = $entityTypeManager;
......@@ -271,7 +273,7 @@ class UWService implements UWServiceInterface {
/**
* {@inheritDoc}
*/
public function uwGetMenu(string $menu_name = 'main', $include_parent_in_count = FALSE): array {
public function uwGetMenu(string $menu_name = 'main', bool $count_menu_items = FALSE, bool $include_parent_in_count = FALSE): array {
// Get the main menu from the simplify menu module.
$menu = $this->simplifyMenu->getMenuTree($menu_name);
......@@ -279,10 +281,12 @@ class UWService implements UWServiceInterface {
// Set it to the menu_tree which is done by simplify menu.
$menu = $menu['menu_tree'];
$menu_items_count = 0;
// If we want to have the count of menu items, then count them.
if ($count_menu_items) {
// Add the count of the menu items.
$menu = $this->uwSetMenuItems($menu, $include_parent_in_count);
// Add the count of the menu items.
$menu = $this->uwSetMenuItems($menu, $include_parent_in_count);
}
return $menu;
}
......@@ -290,7 +294,7 @@ class UWService implements UWServiceInterface {
/**
* {@inheritDoc}
*/
public function uwSetMenuItems($menus, $include_parent_in_count = FALSE): array {
public function uwSetMenuItems(array $menus, bool $include_parent_in_count = FALSE): array {
// Step through the menu and do a few things:
// (a) Remove the Home link (this will be a house icon)
......@@ -370,4 +374,5 @@ class UWService implements UWServiceInterface {
}
}
}
}
......@@ -88,13 +88,15 @@ interface UWServiceInterface {
*
* @param string $menu_name
* A string to the machine name of the menu to get.
* @param $include_parent_in_count
* @param bool $count_menu_items
* A boolean on whether to count the number of menu items.
* @param bool $include_parent_in_count
* A boolean on whether to include the parent in the menu items count.
*
* @return array
* An array of the menu.
*/
public function uwGetMenu(string $menu_name = 'main', $include_parent_in_count = false): array;
public function uwGetMenu(string $menu_name = 'main', bool $count_menu_items = FALSE, bool $include_parent_in_count = FALSE): array;
/**
* A function to setup the menu for UW display.
......@@ -125,22 +127,22 @@ interface UWServiceInterface {
* So it should with the recursive function it will return 11.
* If we include the parent the count will be 12.
*
* @param &$menus
* @param array $menus
* A reference to the array list of menu items.
* @param $include_parent_in_count
* @param bool $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;
public function uwSetMenuItems(array $menus, bool $include_parent_in_count = FALSE): array;
/**
* A function to recursively count the number of menu items in the submenu.
*
* @param $menu
* @param array $menu
* An array that contains the submenu.
* @param $menu_items_count
* @param int &$menu_items_count
* A reference to the integer that is storing the number of menu items.
*/
public function uwCountMenuItems(array $menu, int &$menu_items_count): void;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment