‪TYPO3CMS  ‪main
ExternalViewHelper.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 
20 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
21 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
22 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
23 
49 final class ‪ExternalViewHelper extends AbstractViewHelper
50 {
51  use CompileWithRenderStatic;
52 
53  public function ‪initializeArguments(): void
54  {
55  $this->registerArgument('uri', 'string', 'target URI', true);
56  $this->registerArgument('defaultScheme', 'string', 'scheme the href attribute will be prefixed with if specified $uri does not contain a scheme already', false, 'https');
57  }
58 
59  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string
60  {
61  $uri = $arguments['uri'];
62  $defaultScheme = $arguments['defaultScheme'];
63  $scheme = parse_url($uri, PHP_URL_SCHEME);
64  if ($scheme === null && $defaultScheme !== '') {
65  $uri = $defaultScheme . '://' . $uri;
66  }
67  return $uri;
68  }
69 }
‪TYPO3\CMS\Fluid\ViewHelpers\Uri\ExternalViewHelper
Definition: ExternalViewHelper.php:50
‪TYPO3\CMS\Fluid\ViewHelpers\Uri\ExternalViewHelper\initializeArguments
‪initializeArguments()
Definition: ExternalViewHelper.php:52
‪TYPO3\CMS\Fluid\ViewHelpers\Uri
Definition: ActionViewHelper.php:18
‪TYPO3\CMS\Fluid\ViewHelpers\Uri\ExternalViewHelper\renderStatic
‪static renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: ExternalViewHelper.php:58