‪TYPO3CMS  ‪main
TargetPageIdViewHelper.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
24 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
25 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
26 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
27 
34 final class ‪TargetPageIdViewHelper extends AbstractViewHelper
35 {
36  use CompileWithRenderStatic;
37 
38  public function ‪initializeArguments(): void
39  {
40  $this->registerArgument('target', 'string', 'The target of the redirect.', true);
41  }
42 
46  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string
47  {
48  if (!str_starts_with($arguments['target'] ?? '', 't3://page')) {
49  return '';
50  }
51 
52  try {
53  $linkService = GeneralUtility::makeInstance(LinkService::class);
54  $resolvedLink = $linkService->resolveByStringRepresentation($arguments['target']);
55  return (string)($resolvedLink['pageuid'] ?? '');
56  } catch (UnknownUrnException|UnknownLinkHandlerException $e) {
57  return '';
58  }
59  }
60 }
‪TYPO3\CMS\Redirects\ViewHelpers
Definition: TargetPageIdViewHelper.php:18
‪TYPO3\CMS\Redirects\ViewHelpers\TargetPageIdViewHelper\initializeArguments
‪initializeArguments()
Definition: TargetPageIdViewHelper.php:37
‪TYPO3\CMS\Redirects\ViewHelpers\TargetPageIdViewHelper\renderStatic
‪static renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: TargetPageIdViewHelper.php:45
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Redirects\ViewHelpers\TargetPageIdViewHelper
Definition: TargetPageIdViewHelper.php:35