GetIdViewHelper.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace Opentalent\OtTemplating\ViewHelpers\EventsPage;
  3. use Opentalent\OtCore\Website\OtPageRepository;
  4. use Opentalent\OtCore\ViewHelpers\OtAbstractViewHelper;
  5. use Opentalent\OtCore\Website\OtWebsiteRepository;
  6. use Opentalent\OtTemplating\ViewHelpers\RootPage\GetIdViewHelper as RootPageGetIdViewHelper;
  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, or if the page is disabled
  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 OtAbstractViewHelper
  21. {
  22. public function __construct(
  23. private readonly OtPageRepository $otPageRepository,
  24. private readonly OtWebsiteRepository $otWebsiteRepository,
  25. ) {}
  26. /**
  27. * -- This method is expected by Fluid --
  28. * Declares the viewhelper's parameters
  29. */
  30. public function initializeArguments(): void
  31. {
  32. $this->registerArgument(
  33. 'children',
  34. 'integer',
  35. 'If true, look for the events page of the children structures, instead of the current one',
  36. false,
  37. 0
  38. );
  39. }
  40. /**
  41. * -- This method is expected by Fluid --
  42. * Renders the content as html
  43. *
  44. * @return int|null
  45. */
  46. public function render(): ?int
  47. {
  48. $rootId = $this->otWebsiteRepository->getCurrentRootpageUidFromFEGlobals();
  49. $subpages = $this->otPageRepository->getAllSubpagesForPage($rootId);
  50. $templateName = $this->arguments['children'] == 1 ?
  51. 'OpenTalent.OtTemplating->structuresEvents' :
  52. 'OpenTalent.OtTemplating->events';
  53. foreach ($subpages as $page) {
  54. if ($page['tx_fed_page_controller_action'] === $templateName
  55. & $page['deleted'] == 0
  56. & $page['hidden'] == 0
  57. ) {
  58. return $page['uid'];
  59. }
  60. }
  61. return null;
  62. }
  63. }