TYPO3 CMS  TYPO3_8-7
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 
39 {
43  protected $tagName = 'a';
44 
50  public function initializeArguments()
51  {
52  parent::initializeArguments();
53  $this->registerArgument('uri', 'string', 'The URI that will be put in the href attribute of the rendered link tag', true);
54  $this->registerArgument('defaultScheme', 'string', 'Scheme the href attribute will be prefixed with if specified $uri does not contain a scheme already', false, 'http');
56  $this->registerTagAttribute('name', 'string', 'Specifies the name of an anchor');
57  $this->registerTagAttribute('rel', 'string', 'Specifies the relationship between the current document and the linked document');
58  $this->registerTagAttribute('rev', 'string', 'Specifies the relationship between the linked document and the current document');
59  $this->registerTagAttribute('target', 'string', 'Specifies where to open the linked document');
60  }
61 
66  public function render()
67  {
68  $uri = $this->arguments['uri'];
69  $defaultScheme = $this->arguments['defaultScheme'];
70 
71  $scheme = parse_url($uri, PHP_URL_SCHEME);
72  if ($scheme === null && $defaultScheme !== '') {
73  $uri = $defaultScheme . '://' . $uri;
74  }
75  $this->tag->addAttribute('href', $uri);
76  $this->tag->setContent($this->renderChildren());
77  $this->tag->forceClosingTag(true);
78 
79  return $this->tag->render();
80  }
81 }
registerTagAttribute($name, $type, $description, $required=false, $default=null)