‪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 
19 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
20 
37 class ‪LinkViewHelper extends AbstractTagBasedViewHelper
38 {
42  protected ‪$tagName = 'a';
43 
47  public function ‪initializeArguments()
48  {
49  parent::initializeArguments();
50  $this->registerUniversalTagAttributes();
51  $this->registerTagAttribute('name', 'string', 'Specifies the name of an anchor');
52  $this->registerTagAttribute('rel', 'string', 'Specifies the relationship between the current document and the linked document');
53  $this->registerTagAttribute('rev', 'string', 'Specifies the relationship between the linked document and the current document');
54  $this->registerTagAttribute('target', 'string', 'Specifies where to open the linked document');
55  // @deprecated
56  $this->registerArgument('useCacheHash', 'bool', 'Deprecated: True whether the cache hash should be appended to the URL', false, null);
57  $this->registerArgument('addQueryStringMethod', 'string', 'Method to be used for query string');
58  $this->registerArgument('action', 'string', 'Target action');
59  $this->registerArgument('arguments', 'array', 'Arguments', false, []);
60  $this->registerArgument('section', 'string', 'The anchor to be added to the URI', false, '');
61  $this->registerArgument('format', 'string', 'The requested format, e.g. ".html', false, '');
62  $this->registerArgument('ajax', 'bool', 'TRUE if the URI should be to an AJAX widget, FALSE otherwise.', false, false);
63  $this->registerArgument('absolute', 'bool', 'TRUE if the URI should be absolute, FALSE otherwise', false, false);
64  }
65 
71  public function ‪render()
72  {
73  $ajax = $this->arguments['ajax'];
74 
75  if ($ajax === true) {
76  $uri = $this->‪getAjaxUri();
77  } else {
78  $uri = $this->‪getWidgetUri();
79  }
80  $this->tag->addAttribute('href', $uri);
81  $this->tag->setContent($this->renderChildren());
82  return $this->tag->render();
83  }
84 
90  protected function ‪getAjaxUri()
91  {
92  $action = $this->arguments['action'];
93  $arguments = $this->arguments['arguments'];
94  if ($action === null) {
95  $action = $this->renderingContext->getControllerContext()->getRequest()->getControllerActionName();
96  }
97  $arguments['id'] = ‪$GLOBALS['TSFE']->id;
98  // @todo page type should be configurable
99  $arguments['type'] = 7076;
100  $arguments['fluid-widget-id'] = $this->renderingContext->getControllerContext()->getRequest()->getWidgetContext()->getAjaxWidgetIdentifier();
101  $arguments['action'] = $action;
102  return '?' . http_build_query($arguments, '', '&');
103  }
104 
110  protected function ‪getWidgetUri()
111  {
113  $uriBuilder = $this->renderingContext->getControllerContext()->getUriBuilder();
114  $argumentPrefix = $this->renderingContext->getControllerContext()->getRequest()->getArgumentPrefix();
115  $arguments = $this->hasArgument('arguments') ? $this->arguments['arguments'] : [];
116  if ($this->hasArgument('action')) {
117  $arguments['action'] = $this->arguments['action'];
118  }
119  if ($this->hasArgument('format') && $this->arguments['format'] !== '') {
120  $arguments['format'] = $this->arguments['format'];
121  }
122  if (isset($arguments['useCacheHash'])) {
123  trigger_error('Using the argument "useCacheHash" in <f:widget.link> ViewHelper has no effect anymore. Remove the argument in your fluid template, as it will result in a fatal error.', E_USER_DEPRECATED);
124  }
125  $uriBuilder->reset()
126  ->setArguments([$argumentPrefix => $arguments])
127  ->setSection($this->arguments['section'])
128  ->setAddQueryString(true)
129  ->setArgumentsToBeExcludedFromQueryString([$argumentPrefix, 'cHash'])
130  ->setFormat($this->arguments['format'])
131  ->setCreateAbsoluteUri($this->arguments['absolute'])
132  ;
133 
134  $addQueryStringMethod = $this->arguments['addQueryStringMethod'] ?? null;
135  if (is_string($addQueryStringMethod)) {
136  $uriBuilder->setAddQueryStringMethod($addQueryStringMethod);
137  }
138 
139  return $uriBuilder->build();
140  }
141 }
‪TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder
Definition: UriBuilder.php:39
‪TYPO3\CMS\Fluid\ViewHelpers\Widget
Definition: AutocompleteViewHelper.php:16
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5