1<?php 2namespace TYPO3\CMS\Fluid\ViewHelpers\Be; 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 17use TYPO3\CMS\Backend\Routing\UriBuilder; 18use TYPO3\CMS\Core\Utility\GeneralUtility; 19use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper; 20 21/** 22 * A ViewHelper for creating URIs to modules. 23 * 24 * Examples 25 * ======== 26 * 27 * URI to the web_ts module on page 92:: 28 * 29 * <f:be.link route="web_ts" parameters="{id: 92}">Go to web_ts</f:be.link> 30 * 31 * ``<a href="/typo3/index.php?route=%2module%2web_ts%2&moduleToken=b6e9c9f?id=92">Go to web_ts</a>`` 32 */ 33class LinkViewHelper extends AbstractTagBasedViewHelper 34{ 35 36 /** 37 * @var string 38 */ 39 protected $tagName = 'a'; 40 41 /** 42 * Arguments initialization 43 * 44 * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception 45 */ 46 public function initializeArguments() 47 { 48 parent::initializeArguments(); 49 $this->registerArgument('route', 'string', 'The name of the route', true); 50 $this->registerArgument('parameters', 'array', 'An array of parameters', false, []); 51 $this->registerArgument('referenceType', 'string', 'The type of reference to be generated (one of the constants)', false, UriBuilder::ABSOLUTE_PATH); 52 $this->registerTagAttribute('name', 'string', 'Specifies the name of an anchor'); 53 $this->registerTagAttribute( 54 'rel', 55 'string', 56 'Specifies the relationship between the current document and the linked document' 57 ); 58 $this->registerTagAttribute( 59 'rev', 60 'string', 61 'Specifies the relationship between the linked document and the current document' 62 ); 63 $this->registerTagAttribute('target', 'string', 'Specifies where to open the linked document'); 64 $this->registerUniversalTagAttributes(); 65 } 66 67 /** 68 * @return string Rendered link 69 */ 70 public function render() 71 { 72 $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); 73 $route = $this->arguments['route']; 74 $parameters = $this->arguments['parameters']; 75 $referenceType = $this->arguments['referenceType']; 76 77 $uri = $uriBuilder->buildUriFromRoute($route, $parameters, $referenceType); 78 79 $this->tag->addAttribute('href', $uri); 80 $this->tag->setContent($this->renderChildren()); 81 $this->tag->forceClosingTag(true); 82 83 return $this->tag->render(); 84 } 85} 86