‪TYPO3CMS  11.5
ExternalViewHelper.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
19 
48 class ‪ExternalViewHelper extends AbstractTagBasedViewHelper
49 {
53  protected ‪$tagName = 'a';
54 
58  public function ‪initializeArguments()
59  {
60  parent::initializeArguments();
61  $this->registerArgument('uri', 'string', 'The URI that will be put in the href attribute of the rendered link tag', true);
62  $this->registerArgument('defaultScheme', 'string', 'Scheme the href attribute will be prefixed with if specified $uri does not contain a scheme already', false, 'https');
63  $this->registerUniversalTagAttributes();
64  $this->registerTagAttribute('name', 'string', 'Specifies the name of an anchor');
65  $this->registerTagAttribute('rel', 'string', 'Specifies the relationship between the current document and the linked document');
66  $this->registerTagAttribute('rev', 'string', 'Specifies the relationship between the linked document and the current document');
67  $this->registerTagAttribute('target', 'string', 'Specifies where to open the linked document');
68  }
69 
73  public function ‪render()
74  {
75  $uri = $this->arguments['uri'];
76  $defaultScheme = $this->arguments['defaultScheme'];
77 
78  $scheme = parse_url($uri, PHP_URL_SCHEME);
79  if ($scheme === null && $defaultScheme !== '') {
80  $uri = $defaultScheme . '://' . $uri;
81  }
82  $this->tag->addAttribute('href', $uri);
83  $this->tag->setContent($this->renderChildren());
84  $this->tag->forceClosingTag(true);
85 
86  return $this->tag->render();
87  }
88 }