| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- namespace Opentalent\OtTemplating\ViewHelpers;
- use Closure;
- use Opentalent\OtCore\Page\OtPageRepository;
- use Opentalent\OtCore\ViewHelpers\OtAbstractViewHelper;
- use Opentalent\OtTemplating\ViewHelpers\RootPage\GetIdViewHelper;
- use TYPO3\CMS\Core\Utility\GeneralUtility;
- use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
- use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
- /**
- * Returns the uid of the page with the given slug
- * if it exists in the current website,
- * else returns null
- *
- * {namespace ot=Opentalent\OtTemplating\ViewHelpers}
- *
- * {ot:getPageUid(slug: 'foo')}
- *
- * @package Opentalent\OtTemplating\ViewHelpers
- */
- class GetPageUidViewHelper extends OtAbstractViewHelper
- {
- /**
- * -- This method is expected by Fluid --
- * Declares the viewhelper's parameters
- */
- public function initializeArguments()
- {
- $this->registerArgument(
- 'slug',
- 'string',
- 'The slug of the researched page',
- true
- );
- }
- /**
- * -- 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 = GetIdViewHelper::renderStatic(
- $arguments,
- $renderChildrenClosure,
- $renderingContext
- );
- $pageRepository = GeneralUtility::makeInstance(OtPageRepository::class);
- $subpages = $pageRepository->getAllSubpagesForPage($rootId);
- foreach ($subpages as $page) {
- if ($page['slug'] === $arguments['slug']) {
- return $page['uid'];
- }
- }
- return null;
- }
- }
|