‪TYPO3CMS  9.5
LinkViewHelper.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 
19 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
20 
33 class ‪LinkViewHelper extends AbstractTagBasedViewHelper
34 {
35 
39  protected ‪$tagName = 'a';
40 
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 
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 }
‪TYPO3\CMS\Fluid\ViewHelpers\Be
Definition: AbstractBackendViewHelper.php:2
‪TYPO3\CMS\Backend\Routing\UriBuilder\ABSOLUTE_PATH
‪const ABSOLUTE_PATH
Definition: UriBuilder.php:44
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:35
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45