GetUriViewHelper.php 1.3 KB

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