GetUriViewHelper.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace Opentalent\OtTemplating\ViewHelpers\NewsPage;
  3. use Opentalent\OtCore\ViewHelpers\OtAbstractViewHelper;
  4. use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
  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 OtAbstractViewHelper
  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. return $uriBuilder->setTargetPageUid($pageUid)->build();
  40. }
  41. }