‪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\ViewHelper\AbstractTagBasedViewHelper;
21 
50 final class ‪ExternalViewHelper extends AbstractTagBasedViewHelper
51 {
55  protected ‪$tagName = 'a';
56 
57  public function ‪initializeArguments(): void
58  {
59  parent::initializeArguments();
60  $this->registerArgument('uri', 'string', 'The URI that will be put in the href attribute of the rendered link tag', true);
61  $this->registerArgument('defaultScheme', 'string', 'Scheme the href attribute will be prefixed with if specified $uri does not contain a scheme already', false, 'https');
62  $this->registerUniversalTagAttributes();
63  $this->registerTagAttribute('name', 'string', 'Specifies the name of an anchor');
64  $this->registerTagAttribute('rel', 'string', 'Specifies the relationship between the current document and the linked document');
65  $this->registerTagAttribute('rev', 'string', 'Specifies the relationship between the linked document and the current document');
66  $this->registerTagAttribute('target', 'string', 'Specifies where to open the linked document');
67  }
68 
69  public function ‪render(): string
70  {
71  $uri = $this->arguments['uri'];
72  $defaultScheme = $this->arguments['defaultScheme'];
73 
74  $scheme = parse_url($uri, PHP_URL_SCHEME);
75  if ($scheme === null && $defaultScheme !== '') {
76  $uri = $defaultScheme . '://' . $uri;
77  }
78  $this->tag->addAttribute('href', $uri);
79  $this->tag->setContent($this->renderChildren());
80  $this->tag->forceClosingTag(true);
81 
82  return $this->tag->render();
83  }
84 }