| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- namespace Opentalent\OtTemplating\ViewHelpers\EventsPage;
- use Closure;
- use Opentalent\OtCore\Website\OtPageRepository;
- use Opentalent\OtCore\ViewHelpers\OtAbstractViewHelper;
- use TYPO3\CMS\Core\Utility\GeneralUtility;
- use TYPO3\CMS\Extbase\Object\ObjectManager;
- use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
- /**
- * Retrieves and returns the uid of the events' page of the current site
- * The events page is the first page found with the template 'OpenTalent.OtTemplating->events'
- * Returns null if no such page is found, or if the page is disabled
- *
- * Call it in fluid templates with:
- *
- * {namespace ot=Opentalent\OtTemplating\ViewHelpers}
- *
- * {ot:eventsPage.getId()}
- *
- * @package Opentalent\OtTemplating\ViewHelpers
- */
- class GetIdViewHelper extends OtAbstractViewHelper
- {
- /**
- * -- This method is expected by Fluid --
- * Declares the viewhelper's parameters
- */
- public function initializeArguments()
- {
- $this->registerArgument(
- 'children',
- 'integer',
- 'If true, look for the events page of the children structures, instead of the current one',
- false,
- 0
- );
- }
- /**
- * -- This method is expected by Fluid --
- * Renders the content as html
- *
- * @param array $arguments
- * @param Closure $renderChildrenClosure
- * @param RenderingContextInterface $renderingContext
- * @return int|null
- */
- public static function renderStatic(
- array $arguments,
- Closure $renderChildrenClosure,
- RenderingContextInterface $renderingContext
- ) {
- $rootId = \Opentalent\OtTemplating\ViewHelpers\RootPage\GetIdViewHelper::renderStatic(
- $arguments,
- $renderChildrenClosure,
- $renderingContext
- );
- $pageRepository = GeneralUtility::makeInstance(ObjectManager::class)->get(OtPageRepository::class);
- $subpages = $pageRepository->getAllSubpagesForPage($rootId);
- $templateName = $arguments['children'] == 1 ?
- 'OpenTalent.OtTemplating->structuresEvents' :
- 'OpenTalent.OtTemplating->events';
- foreach ($subpages as $page) {
- if ($page['tx_fed_page_controller_action'] === $templateName
- & $page['deleted'] == 0
- & $page['hidden'] == 0
- ) {
- return $page['uid'];
- }
- }
- return null;
- }
- }
|