‪TYPO3CMS  ‪main
NormalizedUrlViewHelper.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 
22 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
23 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
24 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithContentArgumentAndRenderStatic;
25 
50 final class ‪NormalizedUrlViewHelper extends AbstractViewHelper
51 {
52  use CompileWithContentArgumentAndRenderStatic;
53 
54  public function ‪initializeArguments(): void
55  {
56  $this->registerArgument('pathOrUrl', 'string', 'Absolute path to file using EXT: syntax or URL.');
57  }
58 
62  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string
63  {
64  $pathOrUrl = $renderChildrenClosure();
65  if (‪PathUtility::hasProtocolAndScheme($pathOrUrl)) {
66  return $pathOrUrl;
67  }
68  return GeneralUtility::locationHeaderUrl(‪PathUtility::getPublicResourceWebPath((string)$pathOrUrl));
69  }
70 
74  public function ‪resolveContentArgumentName(): string
75  {
76  return 'pathOrUrl';
77  }
78 }
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:27
‪TYPO3\CMS\Core\ViewHelpers\NormalizedUrlViewHelper\renderStatic
‪static renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: NormalizedUrlViewHelper.php:61
‪TYPO3\CMS\Core\ViewHelpers\NormalizedUrlViewHelper\resolveContentArgumentName
‪resolveContentArgumentName()
Definition: NormalizedUrlViewHelper.php:73
‪TYPO3\CMS\Core\ViewHelpers\NormalizedUrlViewHelper\initializeArguments
‪initializeArguments()
Definition: NormalizedUrlViewHelper.php:53
‪TYPO3\CMS\Core\Utility\PathUtility\getPublicResourceWebPath
‪static getPublicResourceWebPath(string $resourcePath, bool $prefixWithSitePath=true)
Definition: PathUtility.php:97
‪TYPO3\CMS\Core\ViewHelpers
Definition: IconForRecordViewHelper.php:18
‪TYPO3\CMS\Core\ViewHelpers\NormalizedUrlViewHelper
Definition: NormalizedUrlViewHelper.php:51
‪TYPO3\CMS\Core\Utility\PathUtility\hasProtocolAndScheme
‪static hasProtocolAndScheme(string $path)
Definition: PathUtility.php:445
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52