Skip to content
Snippets Groups Projects
Commit 9a2168e9 authored by Eric Bremner's avatar Eric Bremner
Browse files

ISTWCMS-4923: adding else to check menu items so that we don't run code if the...

ISTWCMS-4923: adding else to check menu items so that we don't run code if the menu link is inaccessible
parent 4bf27348
No related branches found
No related tags found
1 merge request!119Feature/istwcms 4923 ebremner inaccessible menu links
......@@ -709,23 +709,25 @@ class UWService implements UWServiceInterface {
if ($m['text'] == 'Inaccessible') {
unset($menu[$key]);
}
else {
// 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']);
// 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']);
// Get the path from the URL of the menu link.
$path = $this->pathAliasManager->getPathByAlias('/' . $alias);
// Get the path from the URL of the menu link.
$path = $this->pathAliasManager->getPathByAlias('/' . $alias);
// Check if it is a node path and if so check if published.
if (preg_match('/^node\/(\d+)$/', $path, $matches)) {
// Check if it is a node path and if so check if published.
if (preg_match('/^node\/(\d+)$/', $path, $matches)) {
// Load in the node based on the path.
$node = $this->entityTypeManager->getStorage('node')->load($matches[1]);
// 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]);
// If the node is unpublished, remove it from the menus.
if ($node->status->value == 0) {
unset($menu[$key]);
}
}
}
}
......
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