GetIdViewHelper.php 1.1 KB

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