‪TYPO3CMS  10.4
LinkViewHelper.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
20 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
21 
34 class ‪LinkViewHelper extends AbstractTagBasedViewHelper
35 {
36 
40  protected ‪$tagName = 'a';
41 
47  public function ‪initializeArguments()
48  {
49  parent::initializeArguments();
50  $this->registerArgument('route', 'string', 'The name of the route', true);
51  $this->registerArgument('parameters', 'array', 'An array of parameters', false, []);
52  $this->registerArgument('referenceType', 'string', 'The type of reference to be generated (one of the constants)', false, ‪UriBuilder::ABSOLUTE_PATH);
53  $this->registerTagAttribute('name', 'string', 'Specifies the name of an anchor');
54  $this->registerTagAttribute(
55  'rel',
56  'string',
57  'Specifies the relationship between the current document and the linked document'
58  );
59  $this->registerTagAttribute(
60  'rev',
61  'string',
62  'Specifies the relationship between the linked document and the current document'
63  );
64  $this->registerTagAttribute('target', 'string', 'Specifies where to open the linked document');
65  $this->registerUniversalTagAttributes();
66  }
67 
71  public function ‪render()
72  {
73  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
74  $route = $this->arguments['route'];
75  $parameters = $this->arguments['parameters'];
76  $referenceType = $this->arguments['referenceType'];
77 
78  $uri = $uriBuilder->buildUriFromRoute($route, $parameters, $referenceType);
79 
80  $this->tag->addAttribute('href', $uri);
81  $this->tag->setContent($this->renderChildren());
82  $this->tag->forceClosingTag(true);
83 
84  return $this->tag->render();
85  }
86 }
‪TYPO3\CMS\Fluid\ViewHelpers\Be
Definition: AbstractBackendViewHelper.php:16
‪TYPO3\CMS\Backend\Routing\UriBuilder\ABSOLUTE_PATH
‪const ABSOLUTE_PATH
Definition: UriBuilder.php:47
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:38
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46