GetUriViewHelper.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace Opentalent\OtTemplating\ViewHelpers\EventsPage;
  3. use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
  4. use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
  5. /**
  6. * Retrieves and returns the Uri to the events page of the current site
  7. * The events page is the first page found with the template 'OpenTalent.OtTemplating->events'
  8. * Return an empty string if no such page is found
  9. *
  10. * Call it in fluid templates with:
  11. *
  12. * {namespace ot=Opentalent\OtTemplating\ViewHelpers}
  13. *
  14. * {ot:eventsPage.getUri()}
  15. *
  16. * @package Opentalent\OtTemplating\ViewHelpers
  17. */
  18. class GetUriViewHelper extends AbstractViewHelper
  19. {
  20. /**
  21. * -- This method is expected by Fluid --
  22. * Renders the content as html
  23. *
  24. * @param array $arguments
  25. * @param \Closure $renderChildrenClosure
  26. * @param RenderingContextInterface $renderingContext
  27. * @return string|null
  28. */
  29. public static function renderStatic(
  30. array $arguments,
  31. \Closure $renderChildrenClosure,
  32. RenderingContextInterface $renderingContext
  33. ) {
  34. $pageUid = GetIdViewHelper::renderStatic($arguments, $renderChildrenClosure, $renderingContext);
  35. if ($pageUid == null) {
  36. return '';
  37. }
  38. $uriBuilder = $renderingContext->getControllerContext()->getUriBuilder();
  39. $uri = $uriBuilder->setTargetPageUid($pageUid)->build();
  40. return $uri;
  41. }
  42. }