diff --git a/core-bundle/src/Resources/contao/modules/Module.php b/core-bundle/src/Resources/contao/modules/Module.php index f69d550762c..2e0fcd3356d 100644 --- a/core-bundle/src/Resources/contao/modules/Module.php +++ b/core-bundle/src/Resources/contao/modules/Module.php @@ -351,11 +351,41 @@ protected function renderNavigation($pid, $level=1, $host=null, $language=null) break; } - $row = $objSubpage->row(); - $trail = \in_array($objSubpage->id, $objPage->trail); + $items[] = $this->compileNavigationRow($objPage, $objSubpage, $subitems, $href); + } + } + + // Add classes first and last + if (!empty($items)) + { + $last = \count($items) - 1; - // Use the path without query string to check for active pages (see #480) - list($path) = explode('?', Environment::get('request'), 2); + $items[0]['class'] = trim($items[0]['class'] . ' first'); + $items[$last]['class'] = trim($items[$last]['class'] . ' last'); + } + + $objTemplate->items = $items; + + return !empty($items) ? $objTemplate->parse() : ''; + } + + /** + * Compile the navigation row and return it as array + * + * @param PageModel $objPage + * @param PageModel $objSubpage + * @param string $subitems + * @param string $href + * + * @return array + */ + protected function compileNavigationRow($objPage, $objSubpage, $subitems, $href) + { + $row = $objSubpage->row(); + $trail = \in_array($objSubpage->id, $objPage->trail); + + // Use the path without query string to check for active pages (see #480) + list($path) = explode('?', Environment::get('request'), 2); // Active page if (($objPage->id == $objSubpage->id || ($objSubpage->type == 'forward' && $objPage->id == $objSubpage->jumpTo)) && !($this instanceof ModuleSitemap) && $href == $path) @@ -363,77 +393,62 @@ protected function renderNavigation($pid, $level=1, $host=null, $language=null) // Mark active forward pages (see #4822) $strClass = (($objSubpage->type == 'forward' && $objPage->id == $objSubpage->jumpTo) ? 'forward' . ($trail ? ' trail' : '') : 'active') . (($subitems != '') ? ' submenu' : '') . ($objSubpage->protected ? ' protected' : '') . ($objSubpage->cssClass ? ' ' . $objSubpage->cssClass : ''); - $row['isActive'] = true; - $row['isTrail'] = false; - } + $row['isActive'] = true; + $row['isTrail'] = false; + } // Regular page else { $strClass = (($subitems != '') ? 'submenu' : '') . ($objSubpage->protected ? ' protected' : '') . ($trail ? ' trail' : '') . ($objSubpage->cssClass ? ' ' . $objSubpage->cssClass : ''); - // Mark pages on the same level (see #2419) - if ($objSubpage->pid == $objPage->pid) - { - $strClass .= ' sibling'; - } - - $row['isActive'] = false; - $row['isTrail'] = $trail; - } - - $row['subitems'] = $subitems; - $row['class'] = trim($strClass); - $row['title'] = StringUtil::specialchars($objSubpage->title, true); - $row['pageTitle'] = StringUtil::specialchars($objSubpage->pageTitle, true); - $row['link'] = $objSubpage->title; - $row['href'] = $href; - $row['rel'] = ''; - $row['nofollow'] = (strncmp($objSubpage->robots, 'noindex,nofollow', 16) === 0); // backwards compatibility - $row['target'] = ''; - $row['description'] = str_replace(array("\n", "\r"), array(' ', ''), $objSubpage->description); - - // Override the link target - if ($objSubpage->type == 'redirect' && $objSubpage->target) - { - $row['target'] = ' target="_blank"'; - } - - $arrRel = array(); + // Mark pages on the same level (see #2419) + if ($objSubpage->pid == $objPage->pid) + { + $strClass .= ' sibling'; + } - if (strncmp($objSubpage->robots, 'noindex,nofollow', 16) === 0) - { - $arrRel[] = 'nofollow'; - } + $row['isActive'] = false; + $row['isTrail'] = $trail; + } - if ($objSubpage->type == 'redirect' && $objSubpage->target) - { - $arrRel[] = 'noreferrer'; - $arrRel[] = 'noopener'; - } + $row['subitems'] = $subitems; + $row['class'] = trim($strClass); + $row['title'] = StringUtil::specialchars($objSubpage->title, true); + $row['pageTitle'] = StringUtil::specialchars($objSubpage->pageTitle, true); + $row['link'] = $objSubpage->title; + $row['href'] = $href; + $row['rel'] = ''; + $row['nofollow'] = (strncmp($objSubpage->robots, 'noindex,nofollow', 16) === 0); // backwards compatibility + $row['target'] = ''; + $row['description'] = str_replace(array("\n", "\r"), array(' ', ''), $objSubpage->description); + + // Override the link target + if ($objSubpage->type == 'redirect' && $objSubpage->target) + { + $row['target'] = ' target="_blank"'; + } - // Override the rel attribute - if (!empty($arrRel)) - { - $row['rel'] = ' rel="' . implode(' ', $arrRel) . '"'; - } + $arrRel = array(); - $items[] = $row; - } + if (strncmp($objSubpage->robots, 'noindex,nofollow', 16) === 0) + { + $arrRel[] = 'nofollow'; } - // Add classes first and last - if (!empty($items)) + if ($objSubpage->type == 'redirect' && $objSubpage->target) { - $last = \count($items) - 1; - - $items[0]['class'] = trim($items[0]['class'] . ' first'); - $items[$last]['class'] = trim($items[$last]['class'] . ' last'); + $arrRel[] = 'noreferrer'; + $arrRel[] = 'noopener'; } - $objTemplate->items = $items; + // Override the rel attribute + if (!empty($arrRel)) + { + $row['rel'] = ' rel="' . implode(' ', $arrRel) . '"'; + } - return !empty($items) ? $objTemplate->parse() : ''; + return $row; } /**