Wrapper service for \TYPO3\CMS\Frontend\Page\PageRepository including static caches for menus, rootlines, pages and page overlays to be implemented in viewhelpers by replacing calls to \TYPO3\CMS\Frontend\Page\PageRepository::getMenu() and the like.
Inheritance: implements TYPO3\CMS\Core\SingletonInterface
Beispiel #1
0
 /**
  * @return mixed
  */
 public function render()
 {
     $pageUid = (int) $this->arguments['pageUid'];
     if (0 === $pageUid) {
         $pageUid = $GLOBALS['TSFE']->id;
     }
     $rootLineData = $this->pageService->getRootLine($pageUid);
     return $this->renderChildrenWithVariableOrReturnInput($rootLineData);
 }
 /**
  * @param array $arguments
  * @return boolean
  */
 protected static function evaluateCondition($arguments = null)
 {
     $pageUid = $arguments['pageUid'];
     $includeHiddenInMenu = (bool) $arguments['includeHiddenInMenu'];
     $includeAccessProtected = (bool) $arguments['includeAccessProtected'];
     if (null === $pageUid || true === empty($pageUid) || 0 === (int) $pageUid) {
         $pageUid = $GLOBALS['TSFE']->id;
     }
     if (self::$pageService === null) {
         $objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
         self::$pageService = $objectManager->get('FluidTYPO3\\Vhs\\Service\\PageService');
     }
     $menu = self::$pageService->getMenu($pageUid, [], $includeHiddenInMenu, false, $includeAccessProtected);
     return 0 < count($menu);
 }
 /**
  * @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;
 }
Beispiel #4
0
 /**
  * @return string
  */
 public function render()
 {
     if ('BE' === TYPO3_MODE) {
         return null;
     }
     $languages = $this->arguments['languages'];
     if (true === $languages instanceof \Traversable) {
         $languages = iterator_to_array($languages);
     } elseif (true === is_string($languages)) {
         $languages = GeneralUtility::trimExplode(',', $languages, true);
     } else {
         $languages = (array) $languages;
     }
     $pageUid = (int) $this->arguments['pageUid'];
     if (0 === $pageUid) {
         $pageUid = $GLOBALS['TSFE']->id;
     }
     $normalWhenNoLanguage = $this->arguments['normalWhenNoLanguage'];
     $addQueryString = $this->arguments['addQueryString'];
     /** @var UriBuilder $uriBuilder */
     $uriBuilder = $this->controllerContext->getUriBuilder();
     $uriBuilder = $uriBuilder->reset()->setTargetPageUid($pageUid)->setCreateAbsoluteUri(true)->setAddQueryString($addQueryString);
     $this->tagBuilder->reset();
     $this->tagBuilder->setTagName('link');
     $this->tagBuilder->addAttribute('rel', 'alternate');
     /** @var PageRenderer $pageRenderer */
     $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
     $usePageRenderer = 1 !== (int) $GLOBALS['TSFE']->config['config']['disableAllHeaderCode'];
     $output = '';
     foreach ($languages as $languageUid => $languageName) {
         if (false === $this->pageService->hidePageForLanguageUid($pageUid, $languageUid, $normalWhenNoLanguage)) {
             $uri = $uriBuilder->setArguments(array('L' => $languageUid))->build();
             $this->tagBuilder->addAttribute('href', $uri);
             $this->tagBuilder->addAttribute('hreflang', $languageName);
             $renderedTag = $this->tagBuilder->render();
             if (true === $usePageRenderer) {
                 $pageRenderer->addMetaTag($renderedTag);
             } else {
                 $output .= $renderedTag . LF;
             }
         }
     }
     if (false === $usePageRenderer) {
         return trim($output);
     }
     return null;
 }
Beispiel #5
0
 /**
  * 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();
 }