diff --git a/src/Service/UWService.php b/src/Service/UWService.php index cb0d6fcf1d8a1f246411ede1d873ea68cc96a875..c6be1b059f0cb8861c1228ad6b41450851234e7e 100644 --- a/src/Service/UWService.php +++ b/src/Service/UWService.php @@ -293,20 +293,43 @@ class UWService implements UWServiceInterface { */ public function uwGetMenu(string $menu_name = 'main', bool $count_menu_items = FALSE, bool $include_parent_in_count = FALSE): array { - // The base path, need this for removing when on subfoldered sites, - // for example d8/fdsu5/, we need to remove the fdsu5 from the path - // alias. - global $base_path; - // Get the main menu from the simplify menu module. $menu = $this->simplifyMenu->getMenuTree($menu_name); // Set it to the menu_tree which is done by simplify menu. $menu = $menu['menu_tree']; + // Ensure that we only get the published menu items. + $this->uwCheckPublishedMenuItems($menu); + + // 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); + } + + return $menu; + } + + /** + * {@inheritDoc} + */ + public function uwCheckPublishedMenuItems(&$menu): void { + + // The base path, need this for removing when on subfoldered sites, + // for example d8/fdsu5/, we need to remove the fdsu5 from the path + // alias. + global $base_path; + // Step through each menu and ensure that it is published. foreach ($menu as $key => $m) { + // If there is a submenu (i.e. children), process it first. + if (isset($m['submenu'])) { + $this->uwCheckPublishedMenuItems($menu[$key]['submenu']); + } + // Remove the base path from the url so that we can get // the actual content from the path alias. $alias = str_replace($base_path, '', $m['url']); @@ -326,15 +349,6 @@ class UWService implements UWServiceInterface { } } } - - // 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); - } - - return $menu; } /** diff --git a/src/Service/UWServiceInterface.php b/src/Service/UWServiceInterface.php index 93714b1bc5e2ff1366d6e94ac9ce4d38f3954c13..c837c74dda234b82a646e06274ca37c7c7234d21 100644 --- a/src/Service/UWServiceInterface.php +++ b/src/Service/UWServiceInterface.php @@ -98,6 +98,14 @@ interface UWServiceInterface { */ public function uwGetMenu(string $menu_name = 'main', bool $count_menu_items = FALSE, bool $include_parent_in_count = FALSE): array; + /** + * Function to check that all menu links are published. + * + * @param $menu + * The array of menus. + */ + public function uwCheckPublishedMenuItems(&$menu): void; + /** * A function to setup the menu for UW display. *