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