GetIdViewHelper.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. * Declares the viewhelper's parameters
  27. */
  28. public function initializeArguments()
  29. {
  30. $this->registerArgument(
  31. 'children',
  32. 'integer',
  33. 'If true, look for the events page of the children structures, instead of the current one',
  34. false,
  35. 0
  36. );
  37. }
  38. /**
  39. * -- This method is expected by Fluid --
  40. * Renders the content as html
  41. *
  42. * @param array $arguments
  43. * @param Closure $renderChildrenClosure
  44. * @param RenderingContextInterface $renderingContext
  45. * @return int|null
  46. */
  47. public static function renderStatic(
  48. array $arguments,
  49. Closure $renderChildrenClosure,
  50. RenderingContextInterface $renderingContext
  51. ) {
  52. $rootId = \Opentalent\OtTemplating\ViewHelpers\RootPage\GetIdViewHelper::renderStatic(
  53. $arguments,
  54. $renderChildrenClosure,
  55. $renderingContext
  56. );
  57. $pageRepository = GeneralUtility::makeInstance(ObjectManager::class)->get(OtPageRepository::class);
  58. $subpages = $pageRepository->getAllSubpagesForPage($rootId);
  59. $templateName = $arguments['children'] == 1 ?
  60. 'OpenTalent.OtTemplating->structuresEvents' :
  61. 'OpenTalent.OtTemplating->events';
  62. foreach ($subpages as $page) {
  63. if ($page['tx_fed_page_controller_action'] === $templateName
  64. & $page['deleted'] == 0
  65. & $page['hidden'] == 0
  66. ) {
  67. return $page['uid'];
  68. }
  69. }
  70. return null;
  71. }
  72. }