GetIdViewHelper.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace Opentalent\OtTemplating\ViewHelpers\NewsPage;
  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. public function __construct(
  25. private readonly OtPageRepository $otPageRepository,
  26. ) {}
  27. /**
  28. * -- This method is expected by Fluid --
  29. * Renders the content as html
  30. *
  31. * @return int|null
  32. */
  33. public function render(): ?int
  34. {
  35. $rootId = \Opentalent\OtTemplating\ViewHelpers\RootPage\GetIdViewHelper::renderStatic(
  36. $this->arguments,
  37. $this->renderChildrenClosure,
  38. $this->renderingContext
  39. );
  40. $subpages = $this->otPageRepository->getAllSubpagesForPage($rootId);
  41. foreach ($subpages as $page) {
  42. if ($page['tx_fed_page_controller_action'] === 'OpenTalent.OtTemplating->news'
  43. & $page['deleted'] == 0
  44. & $page['hidden'] == 0
  45. ) {
  46. return $page['uid'];
  47. }
  48. }
  49. return null;
  50. }
  51. }