| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- namespace Opentalent\OtTemplating\ViewHelpers\Page;
- use Opentalent\OtCore\Website\OtPageRepository;
- use Opentalent\OtCore\ViewHelpers\OtAbstractViewHelper;
- use Opentalent\OtCore\Website\OtWebsiteRepository;
- /**
- * Returns the uid of the first page with the given template in the current website, or null if none
- *
- * {namespace ot=Opentalent\OtTemplating\ViewHelpers}
- *
- * {ot:page.getFirstWithTemplate(template: 'foo')}
- *
- * @package Opentalent\OtTemplating\ViewHelpers
- */
- class GetFirstWithTemplateViewHelper extends OtAbstractViewHelper
- {
- public function __construct(
- private readonly OtPageRepository $otPageRepository,
- private readonly OtWebsiteRepository $otWebsiteRepository,
- ) {}
- /**
- * -- This method is expected by Fluid --
- * Declares the viewhelper's parameters
- */
- public function initializeArguments(): void
- {
- $this->registerArgument(
- 'template',
- 'string',
- "The template's name",
- true
- );
- }
- /**
- * -- This method is expected by Fluid --
- * Renders the content as html
- *
- * @return int|null
- */
- public function render(): ?int
- {
- $rootId = $this->otWebsiteRepository->getCurrentRootpageUidFromFEGlobals();
- $subpages = $this->otPageRepository->getAllSubpagesForPage($rootId);
- $templateName = 'OpenTalent.OtTemplating->' . $this->arguments['template'];
- foreach ($subpages as $page) {
- if ($page['tx_fed_page_controller_action'] === $templateName
- & $page['deleted'] === 0
- & $page['hidden'] === 0
- ) {
- return $page['uid'];
- }
- }
- return null;
- }
- }
|