[TASK] Streamline return tags in phpdocs
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Link / ExternalViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Link;
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 /**
18 * A view helper for creating links to external targets.
19 *
20 * = Examples =
21 *
22 * <code>
23 * <f:link.external uri="http://www.typo3.org" target="_blank">external link</f:link.external>
24 * </code>
25 * <output>
26 * <a href="http://www.typo3.org" target="_blank">external link</a>
27 * </output>
28 *
29 * <code title="custom default scheme">
30 * <f:link.external uri="typo3.org" defaultScheme="ftp">external ftp link</f:link.external>
31 * </code>
32 * <output>
33 * <a href="ftp://typo3.org">external ftp link</a>
34 * </output>
35 *
36 * @api
37 */
38 class ExternalViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper
39 {
40 /**
41 * @var string
42 */
43 protected $tagName = 'a';
44
45 /**
46 * Initialize arguments
47 *
48 * @api
49 */
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');
55 $this->registerUniversalTagAttributes();
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
62 /**
63 * @return string Rendered link
64 * @api
65 */
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 }