GetUriViewHelper.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace Opentalent\OtTemplating\ViewHelpers\RootPage;
  3. use Closure;
  4. use Opentalent\OtCore\Exception\InvalidWebsiteConfigurationException;
  5. use Opentalent\OtCore\Exception\NoSuchWebsiteException;
  6. use Opentalent\OtCore\ViewHelpers\OtAbstractViewHelper;
  7. use Opentalent\OtCore\Website\OtWebsiteRepository;
  8. use TYPO3\CMS\Core\Utility\GeneralUtility;
  9. use TYPO3\CMS\Extbase\Object\ObjectManager;
  10. use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
  11. /**
  12. * Viewhelper to retrieve the Uri of the root page of the current site
  13. * Call it in fluid templates with:
  14. *
  15. * {namespace ot=Opentalent\OtTemplating\ViewHelpers}
  16. *
  17. * {ot:rootPage.getUri()}
  18. *
  19. * @package Opentalent\OtTemplating\ViewHelpers
  20. */
  21. class GetUriViewHelper extends OtAbstractViewHelper
  22. {
  23. public function __construct(
  24. private readonly OtWebsiteRepository $otWebsiteRepository,
  25. ) {}
  26. /**
  27. * -- This method is expected by Fluid --
  28. * Renders the content as html
  29. *
  30. * @return string
  31. * @throws InvalidWebsiteConfigurationException
  32. * @throws NoSuchWebsiteException
  33. */
  34. public function render(): string
  35. {
  36. return $this->otWebsiteRepository->getCurrentSiteRootUriFromFeGlobals();
  37. }
  38. }