GetIdViewHelper.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace Opentalent\OtTemplating\ViewHelpers\RootPage;
  3. use Closure;
  4. use Opentalent\OtCore\Exception\NoSuchWebsiteException;
  5. use Opentalent\OtCore\ViewHelpers\OtAbstractViewHelper;
  6. use Opentalent\OtCore\Website\OtWebsiteRepository;
  7. use TYPO3\CMS\Core\Utility\GeneralUtility;
  8. use TYPO3\CMS\Extbase\Object\ObjectManager;
  9. use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
  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 OtAbstractViewHelper
  21. {
  22. public function __construct(
  23. private readonly OtWebsiteRepository $otWebsiteRepository,
  24. ) {}
  25. /**
  26. * -- This method is expected by Fluid --
  27. * Renders the content as html
  28. *
  29. * @return int|null
  30. * @throws NoSuchWebsiteException
  31. */
  32. public function render(): ?int
  33. {
  34. return $this->otWebsiteRepository->getCurrentRootpageUidFromFEGlobals();
  35. }
  36. }