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; 19 20/** 21 * A ViewHelper for creating URIs to modules. 22 * 23 * Examples 24 * ======== 25 * 26 * URI to the web_ts module on page 92:: 27 * 28 * <f:be.uri route="web_ts" parameters="{id: 92}"/> 29 * 30 * ``/typo3/index.php?M=web_ts&moduleToken=b6e9c9f?id=92`` 31 * 32 * Inline notation:: 33 * 34 * {f:be.uri(route: 'web_ts', parameters: '{id: 92}')} 35 * 36 * ``/typo3/index.php?route=%2module%2web_ts%2&moduleToken=b6e9c9f?id=92`` 37 */ 38class UriViewHelper extends AbstractBackendViewHelper 39{ 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( 52 'referenceType', 53 'string', 54 'The type of reference to be generated (one of the constants)', 55 false, 56 UriBuilder::ABSOLUTE_PATH 57 ); 58 } 59 60 /** 61 * @return string Rendered link 62 */ 63 public function render() 64 { 65 /** @var UriBuilder $uriBuilder */ 66 $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); 67 $route = $this->arguments['route']; 68 $parameters = $this->arguments['parameters']; 69 $referenceType = $this->arguments['referenceType']; 70 $uri = $uriBuilder->buildUriFromRoute($route, $parameters, $referenceType); 71 72 return (string)$uri; 73 } 74} 75