‪TYPO3CMS  9.5
ExternalViewHelper.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
17 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
18 
47 class ‪ExternalViewHelper extends AbstractTagBasedViewHelper
48 {
52  protected ‪$tagName = 'a';
53 
57  public function ‪initializeArguments()
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, 'http');
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 
72  public function ‪render()
73  {
74  $uri = $this->arguments['uri'];
75  $defaultScheme = $this->arguments['defaultScheme'];
76 
77  $scheme = parse_url($uri, PHP_URL_SCHEME);
78  if ($scheme === null && $defaultScheme !== '') {
79  $uri = $defaultScheme . '://' . $uri;
80  }
81  $this->tag->addAttribute('href', $uri);
82  $this->tag->setContent($this->renderChildren());
83  $this->tag->forceClosingTag(true);
84 
85  return $this->tag->render();
86  }
87 }