GetIdViewHelper.php 1.9 KB

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