GetIdViewHelper.php 1.2 KB

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