/** * @param array $pages * @return array */ public function parseMenu(array $pages) { $count = 0; $total = count($pages); $processedPages = []; foreach ($pages as $index => $page) { if (true === $this->pageService->hidePageForLanguageUid($page)) { continue; } $count++; $class = []; $originalPageUid = $page['uid']; $showAccessProtected = (bool) $this->arguments['showAccessProtected']; if ($showAccessProtected) { $pages[$index]['accessProtected'] = $this->pageService->isAccessProtected($page); if (true === $pages[$index]['accessProtected']) { $class[] = $this->arguments['classAccessProtected']; } $pages[$index]['accessGranted'] = $this->pageService->isAccessGranted($page); if (true === $pages[$index]['accessGranted'] && true === $this->pageService->isAccessProtected($page)) { $class[] = $this->arguments['classAccessGranted']; } } $targetPage = $this->pageService->getShortcutTargetPage($page); if ($targetPage !== null) { if ($this->pageService->shouldUseShortcutTarget($this->arguments)) { $pages[$index] = $targetPage; } if ($this->pageService->shouldUseShortcutUid($this->arguments)) { $page['uid'] = $targetPage['uid']; } } if (true === $this->pageService->isActive($originalPageUid, $showAccessProtected)) { $pages[$index]['active'] = true; $class[] = $this->arguments['classActive']; } if (true === $this->pageService->isCurrent($page['uid'])) { $pages[$index]['current'] = true; $class[] = $this->arguments['classCurrent']; } if (0 < count($this->pageService->getMenu($originalPageUid))) { $pages[$index]['hasSubPages'] = true; //TODO: Remove deprecated argument in next major version $class[] = $this->arguments[$this->hasArgument('classHasSubpages') ? 'classHasSubpages' : 'classHasSubPages']; } if (1 === $count) { $class[] = $this->arguments['classFirst']; } if ($count === $total) { $class[] = $this->arguments['classLast']; } $pages[$index]['class'] = implode(' ', $class); $pages[$index]['linktext'] = $this->getItemTitle($pages[$index]); $forceAbsoluteUrl = $this->arguments['forceAbsoluteUrl']; $pages[$index]['link'] = $this->pageService->getItemLink($page, $forceAbsoluteUrl); $processedPages[$index] = $pages[$index]; } return $processedPages; }
/** * Render method * @return NULL|string */ public function render() { // Check if link wizard link $pageUid = $this->arguments['pageUid']; $additionalParameters = (array) $this->arguments['additionalParams']; if (false === is_numeric($pageUid)) { $linkConfig = GeneralUtility::unQuoteFilenames($pageUid, true); if (true === isset($linkConfig[0])) { $pageUid = $linkConfig[0]; } if (true === isset($linkConfig[1]) && '-' !== $linkConfig[1]) { $this->tag->addAttribute('target', $linkConfig[1]); } if (true === isset($linkConfig[2]) && '-' !== $linkConfig[2]) { $this->tag->addAttribute('class', $linkConfig[2]); } if (true === isset($linkConfig[3]) && '-' !== $linkConfig[3]) { $this->tag->addAttribute('title', $linkConfig[3]); } if (true === isset($linkConfig[4]) && '-' !== $linkConfig[4]) { $additionalParametersString = trim($linkConfig[4], '&'); $additionalParametersArray = GeneralUtility::trimExplode('&', $additionalParametersString); foreach ($additionalParametersArray as $parameter) { list($key, $value) = GeneralUtility::trimExplode('=', $parameter); $additionalParameters[$key] = $value; } } } // Get page via pageUid argument or current id $pageUid = (int) $pageUid; if (0 === $pageUid) { $pageUid = $GLOBALS['TSFE']->id; } $showAccessProtected = (bool) $this->arguments['showAccessProtected']; //TODO: Remove handling of deprecated argument if ($this->hasArgument('linkAccessRestrictedPages')) { $showAccessProtected = (bool) $this->arguments['linkAccessRestrictedPages']; } $page = $this->pageService->getPage($pageUid, $showAccessProtected); if (empty($page)) { return null; } $targetPage = $this->pageService->getShortcutTargetPage($page); if ($targetPage !== null) { if ($this->pageService->shouldUseShortcutTarget($this->arguments)) { $page = $targetPage; } if ($this->pageService->shouldUseShortcutUid($this->arguments)) { $pageUid = $targetPage['uid']; } } // Do not render the link, if the page should be hidden $currentLanguageUid = $GLOBALS['TSFE']->sys_language_uid; $hidePage = $this->pageService->hidePageForLanguageUid($page, $currentLanguageUid); if (true === $hidePage) { return null; } // Get the title from the page or page overlay $title = $this->getTitleValue($page); // Check if we should assign page title to the template variable container $pageTitleAs = $this->arguments['pageTitleAs']; if (!empty($pageTitleAs)) { $variables = [$pageTitleAs => $title]; } else { $variables = []; } // Render children to see if an alternative title content should be used $renderedTitle = $this->renderChildrenWithVariables($variables); if (!empty($renderedTitle)) { $title = $renderedTitle; } $class = []; if ($showAccessProtected && $this->pageService->isAccessProtected($page)) { $class[] = $this->arguments['classAccessProtected']; } if ($showAccessProtected && $this->pageService->isAccessGranted($page)) { $class[] = $this->arguments['classAccessGranted']; } $additionalCssClasses = implode(' ', $class); $uriBuilder = $this->controllerContext->getUriBuilder(); $uri = $uriBuilder->reset()->setTargetPageUid($pageUid)->setTargetPageType($this->arguments['pageType'])->setNoCache($this->arguments['noCache'])->setUseCacheHash(!$this->arguments['noCacheHash'])->setSection($this->arguments['section'])->setArguments($additionalParameters)->setCreateAbsoluteUri($this->arguments['absolute'])->setAddQueryString($this->arguments['addQueryString'])->setArgumentsToBeExcludedFromQueryString((array) $this->arguments['argumentsToBeExcludedFromQueryString'])->build(); $this->tag->addAttribute('href', $uri); if (!empty($this->arguments['class'])) { $this->tag->addAttribute('class', $this->arguments['class'] . ' ' . $additionalCssClasses); } else { $this->tag->addAttribute('class', $additionalCssClasses); } $this->tag->setContent($title); return $this->tag->render(); }