Skip to content
Snippets Groups Projects
Commit 433f60e4 authored by Kevin Paxman's avatar Kevin Paxman
Browse files

Merge branch 'feature/ISTWCMS-4923-ebremner-inaccessible-menu-links' into '1.0.x'

Feature/istwcms 4923 ebremner inaccessible menu links

See merge request !119
parents 27935d98 9a2168e9
No related branches found
No related tags found
1 merge request!119Feature/istwcms 4923 ebremner inaccessible menu links
......@@ -674,8 +674,8 @@ class UWService implements UWServiceInterface {
// 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);
// Check that menu links are published and accessible.
$this->uwCheckMenuItems($menu);
// If we want to have the count of menu items, then count them.
if ($count_menu_items) {
......@@ -690,7 +690,7 @@ class UWService implements UWServiceInterface {
/**
* {@inheritDoc}
*/
public function uwCheckPublishedMenuItems(&$menu): void {
public function uwCheckMenuItems(&$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
......@@ -702,25 +702,32 @@ class UWService implements UWServiceInterface {
// If there is a submenu (i.e. children), process it first.
if (isset($m['submenu'])) {
$this->uwCheckPublishedMenuItems($menu[$key]['submenu']);
$this->uwCheckMenuItems($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']);
// If its inaccessible, remove the menu link.
if ($m['text'] == 'Inaccessible') {
unset($menu[$key]);
}
else {
// Get the path from the URL of the menu link.
$path = $this->pathAliasManager->getPathByAlias('/' . $alias);
// 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']);
// Check if it is a node path and if so check if published.
if (preg_match('/^node\/(\d+)$/', $path, $matches)) {
// Get the path from the URL of the menu link.
$path = $this->pathAliasManager->getPathByAlias('/' . $alias);
// Load in the node based on the path.
$node = $this->entityTypeManager->getStorage('node')->load($matches[1]);
// Check if it is a node path and if so check if published.
if (preg_match('/^node\/(\d+)$/', $path, $matches)) {
// If the node is unpublished, remove it from the menus.
if ($node->status->value == 0) {
unset($menu[$key]);
// Load in the node based on the path.
$node = $this->entityTypeManager->getStorage('node')->load($matches[1]);
// If the node is unpublished, remove it from the menus.
if ($node->status->value == 0) {
unset($menu[$key]);
}
}
}
}
......
......@@ -194,7 +194,7 @@ interface UWServiceInterface {
* @param array $menu
* The array of menus.
*/
public function uwCheckPublishedMenuItems(array &$menu): void;
public function uwCheckMenuItems(array &$menu): void;
/**
* A function to setup the menu for UW display.
......
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