GetIdViewHelper.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace Opentalent\OtTemplating\ViewHelpers\EventsPage;
  3. use Closure;
  4. use Opentalent\OtTemplating\Page\OtPageRepository;
  5. use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
  6. use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
  7. /**
  8. * Retrieves and returns the uid of the events' page of the current site
  9. * The events page is the first page found with the template 'OpenTalent.OtTemplating->events'
  10. * Returns null if no such page is found
  11. *
  12. * Call it in fluid templates with:
  13. *
  14. * {namespace ot=Opentalent\OtTemplating\ViewHelpers}
  15. *
  16. * {ot:eventsPage.getId()}
  17. *
  18. * @package Opentalent\OtTemplating\ViewHelpers
  19. */
  20. class GetIdViewHelper extends AbstractViewHelper
  21. {
  22. /**
  23. * -- This method is expected by Fluid --
  24. * Renders the content as html
  25. *
  26. * @param array $arguments
  27. * @param Closure $renderChildrenClosure
  28. * @param RenderingContextInterface $renderingContext
  29. * @return int|null
  30. */
  31. public static function renderStatic(
  32. array $arguments,
  33. Closure $renderChildrenClosure,
  34. RenderingContextInterface $renderingContext
  35. ) {
  36. $rootId = \Opentalent\OtTemplating\ViewHelpers\RootPage\GetIdViewHelper::renderStatic(
  37. $arguments,
  38. $renderChildrenClosure,
  39. $renderingContext
  40. );
  41. $pageRepository = new OtPageRepository();
  42. $subpages = $pageRepository->getAllSubpagesForPage($rootId);
  43. foreach ($subpages as $page) {
  44. if ($page['tx_fed_page_controller_action'] === 'OpenTalent.OtTemplating->events') {
  45. return $page['uid'];
  46. }
  47. }
  48. return null;
  49. }
  50. }