GetIdViewHelper.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace Opentalent\OtTemplating\ViewHelpers\RootPage;
  3. use Closure;
  4. use Opentalent\OtTemplating\Page\OtPageRepository;
  5. use TYPO3\CMS\Core\Utility\GeneralUtility;
  6. use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
  7. use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
  8. /**
  9. * Viewhelper to retrieve the Id of the current site root page
  10. * Call it in fluid templates with:
  11. *
  12. * {namespace ot=Opentalent\OtTemplating\ViewHelpers}
  13. *
  14. * {ot:rootPage.getId()}
  15. *
  16. * @package Opentalent\OtTemplating\ViewHelpers
  17. */
  18. class GetIdViewHelper extends AbstractViewHelper
  19. {
  20. /**
  21. * -- This method is expected by Fluid --
  22. * Renders the content as html
  23. *
  24. * @param array $arguments
  25. * @param Closure $renderChildrenClosure
  26. * @param RenderingContextInterface $renderingContext
  27. * @return int|null
  28. */
  29. public static function renderStatic(
  30. array $arguments,
  31. Closure $renderChildrenClosure,
  32. RenderingContextInterface $renderingContext
  33. ) {
  34. $pageUid = $GLOBALS['TSFE']->id;
  35. $pageRepository = GeneralUtility::makeInstance(OtPageRepository::class);
  36. return $pageRepository->getRootPageFor($pageUid)['uid'];
  37. }
  38. }