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