GetIdViewHelper.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 Opentalent\OtCore\Website\OtWebsiteRepository;
  7. use TYPO3\CMS\Core\Utility\GeneralUtility;
  8. use TYPO3\CMS\Extbase\Object\ObjectManager;
  9. use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
  10. /**
  11. * Retrieves and returns the uid of the events' page of the current site
  12. * The events page is the first page found with the template 'OpenTalent.OtTemplating->events'
  13. * Returns null if no such page is found, or if the page is disabled
  14. *
  15. * Call it in fluid templates with:
  16. *
  17. * {namespace ot=Opentalent\OtTemplating\ViewHelpers}
  18. *
  19. * {ot:eventsPage.getId()}
  20. *
  21. * @package Opentalent\OtTemplating\ViewHelpers
  22. */
  23. class GetIdViewHelper extends OtAbstractViewHelper
  24. {
  25. public function __construct(
  26. private readonly OtPageRepository $otPageRepository,
  27. private readonly OtWebsiteRepository $otWebsiteRepository,
  28. ) {}
  29. /**
  30. * -- This method is expected by Fluid --
  31. * Renders the content as html
  32. *
  33. * @return int|null
  34. */
  35. public function render(): ?int
  36. {
  37. $rootId = $this->otWebsiteRepository->getCurrentRootpageUidFromFEGlobals();
  38. $subpages = $this->otPageRepository->getAllSubpagesForPage($rootId);
  39. foreach ($subpages as $page) {
  40. if ($page['tx_fed_page_controller_action'] === 'OpenTalent.OtTemplating->news'
  41. & $page['deleted'] == 0
  42. & $page['hidden'] == 0
  43. ) {
  44. return $page['uid'];
  45. }
  46. }
  47. return null;
  48. }
  49. }