‪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 
17 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
18 
35 class ‪LinkViewHelper extends AbstractTagBasedViewHelper
36 {
40  protected ‪$tagName = 'a';
41 
45  public function ‪initializeArguments()
46  {
47  parent::initializeArguments();
48  $this->registerUniversalTagAttributes();
49  $this->registerTagAttribute('name', 'string', 'Specifies the name of an anchor');
50  $this->registerTagAttribute('rel', 'string', 'Specifies the relationship between the current document and the linked document');
51  $this->registerTagAttribute('rev', 'string', 'Specifies the relationship between the linked document and the current document');
52  $this->registerTagAttribute('target', 'string', 'Specifies where to open the linked document');
53  $this->registerArgument('useCacheHash', 'bool', 'True whether the cache hash should be appended to the URL', false, false);
54  $this->registerArgument('addQueryStringMethod', 'string', 'Method to be used for query string');
55  $this->registerArgument('action', 'string', 'Target action');
56  $this->registerArgument('arguments', 'array', 'Arguments', false, []);
57  $this->registerArgument('section', 'string', 'The anchor to be added to the URI', false, '');
58  $this->registerArgument('format', 'string', 'The requested format, e.g. ".html', false, '');
59  $this->registerArgument('ajax', 'bool', 'TRUE if the URI should be to an AJAX widget, FALSE otherwise.', false, false);
60  }
61 
67  public function ‪render()
68  {
69  $ajax = $this->arguments['ajax'];
70 
71  if ($ajax === true) {
72  $uri = $this->‪getAjaxUri();
73  } else {
74  $uri = $this->‪getWidgetUri();
75  }
76  $this->tag->addAttribute('href', $uri);
77  $this->tag->setContent($this->renderChildren());
78  return $this->tag->render();
79  }
80 
86  protected function ‪getAjaxUri()
87  {
88  $action = $this->arguments['action'];
89  $arguments = $this->arguments['arguments'];
90  if ($action === null) {
91  $action = $this->renderingContext->getControllerContext()->getRequest()->getControllerActionName();
92  }
93  $arguments['id'] = ‪$GLOBALS['TSFE']->id;
94  // @todo page type should be configurable
95  $arguments['type'] = 7076;
96  $arguments['fluid-widget-id'] = $this->renderingContext->getControllerContext()->getRequest()->getWidgetContext()->getAjaxWidgetIdentifier();
97  $arguments['action'] = $action;
98  return '?' . http_build_query($arguments, null, '&');
99  }
100 
106  protected function ‪getWidgetUri()
107  {
108  $uriBuilder = $this->renderingContext->getControllerContext()->getUriBuilder();
109  $argumentPrefix = $this->renderingContext->getControllerContext()->getRequest()->getArgumentPrefix();
110  $arguments = $this->hasArgument('arguments') ? $this->arguments['arguments'] : [];
111  if ($this->hasArgument('action')) {
112  $arguments['action'] = $this->arguments['action'];
113  }
114  if ($this->hasArgument('format') && $this->arguments['format'] !== '') {
115  $arguments['format'] = $this->arguments['format'];
116  }
117  return $uriBuilder->reset()
118  ->setArguments([$argumentPrefix => $arguments])
119  ->setSection($this->arguments['section'])
120  ->setUseCacheHash($this->arguments['useCacheHash'])
121  ->setAddQueryString(true)
122  ->setAddQueryStringMethod($this->arguments['addQueryStringMethod'])
123  ->setArgumentsToBeExcludedFromQueryString([$argumentPrefix, 'cHash'])
124  ->setFormat($this->arguments['format'])
125  ->build();
126  }
127 }
‪TYPO3\CMS\Fluid\ViewHelpers\Widget
Definition: AutocompleteViewHelper.php:2
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5