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 { ...@@ -32,7 +32,7 @@ class UWService implements UWServiceInterface {
private $database; private $database;
/** /**
* Simplify_menu menu. * Simplify_menu menu items.
* *
* @var \Drupal\simplify_menu\MenuItems * @var \Drupal\simplify_menu\MenuItems
*/ */
...@@ -45,6 +45,8 @@ class UWService implements UWServiceInterface { ...@@ -45,6 +45,8 @@ class UWService implements UWServiceInterface {
* Entity Type Manager from core. * Entity Type Manager from core.
* @param \Drupal\Core\Database\Connection $database * @param \Drupal\Core\Database\Connection $database
* The database entity. * The database entity.
* @param \Drupal\simplify_menu\MenuItems $simplifyMenu
* The simplify_menu menu items.
*/ */
public function __construct(EntityTypeManagerInterface $entityTypeManager, Connection $database, MenuItems $simplifyMenu) { public function __construct(EntityTypeManagerInterface $entityTypeManager, Connection $database, MenuItems $simplifyMenu) {
$this->entityTypeManager = $entityTypeManager; $this->entityTypeManager = $entityTypeManager;
...@@ -271,7 +273,7 @@ class UWService implements UWServiceInterface { ...@@ -271,7 +273,7 @@ class UWService implements UWServiceInterface {
/** /**
* {@inheritDoc} * {@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. // Get the main menu from the simplify menu module.
$menu = $this->simplifyMenu->getMenuTree($menu_name); $menu = $this->simplifyMenu->getMenuTree($menu_name);
...@@ -279,10 +281,12 @@ class UWService implements UWServiceInterface { ...@@ -279,10 +281,12 @@ class UWService implements UWServiceInterface {
// Set it to the menu_tree which is done by simplify menu. // Set it to the menu_tree which is done by simplify menu.
$menu = $menu['menu_tree']; $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. // Add the count of the menu items.
$menu = $this->uwSetMenuItems($menu, $include_parent_in_count); $menu = $this->uwSetMenuItems($menu, $include_parent_in_count);
}
return $menu; return $menu;
} }
...@@ -290,7 +294,7 @@ class UWService implements UWServiceInterface { ...@@ -290,7 +294,7 @@ class UWService implements UWServiceInterface {
/** /**
* {@inheritDoc} * {@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: // 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)
...@@ -370,4 +374,5 @@ class UWService implements UWServiceInterface { ...@@ -370,4 +374,5 @@ class UWService implements UWServiceInterface {
} }
} }
} }
} }
...@@ -88,13 +88,15 @@ interface UWServiceInterface { ...@@ -88,13 +88,15 @@ interface UWServiceInterface {
* *
* @param string $menu_name * @param string $menu_name
* A string to the machine name of the menu to get. * 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. * 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 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. * A function to setup the menu for UW display.
...@@ -125,22 +127,22 @@ interface UWServiceInterface { ...@@ -125,22 +127,22 @@ interface UWServiceInterface {
* 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. * If we include the parent the count will be 12.
* *
* @param &$menus * @param array $menus
* A reference to the array list of menu items. * 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. * A boolean on whether to include the parent in the menu items count.
* *
* @return array * @return array
* An array of the updated menu items. * 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. * A function to recursively count the number of menu items in the submenu.
* *
* @param $menu * @param array $menu
* An array that contains the submenu. * 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. * A reference to the integer that is storing the number of menu items.
*/ */
public function uwCountMenuItems(array $menu, int &$menu_items_count): void; 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