TYPO3 CMS  TYPO3_8-7
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 
33 {
37  protected $tagName = 'a';
38 
44  public function initializeArguments()
45  {
46  parent::initializeArguments();
48  $this->registerTagAttribute('name', 'string', 'Specifies the name of an anchor');
49  $this->registerTagAttribute('rel', 'string', 'Specifies the relationship between the current document and the linked document');
50  $this->registerTagAttribute('rev', 'string', 'Specifies the relationship between the linked document and the current document');
51  $this->registerTagAttribute('target', 'string', 'Specifies where to open the linked document');
52  $this->registerArgument('useCacheHash', 'bool', 'True whether the cache hash should be appended to the URL', false, true);
53  $this->registerArgument('addQueryStringMethod', 'string', 'Method to be used for query string');
54  $this->registerArgument('action', 'string', 'Target action');
55  $this->registerArgument('arguments', 'array', 'Arguments', false, []);
56  $this->registerArgument('section', 'string', 'The anchor to be added to the URI', false, '');
57  $this->registerArgument('format', 'string', 'The requested format, e.g. ".html', false, '');
58  $this->registerArgument('ajax', 'bool', 'TRUE if the URI should be to an AJAX widget, FALSE otherwise.', false, false);
59  }
60 
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->controllerContext->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->controllerContext->getRequest()->getWidgetContext()->getAjaxWidgetIdentifier();
97  $arguments['action'] = $action;
98  return '?' . http_build_query($arguments, null, '&');
99  }
100 
106  protected function getWidgetUri()
107  {
108  $uriBuilder = $this->controllerContext->getUriBuilder();
109  $argumentPrefix = $this->controllerContext->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 }
registerTagAttribute($name, $type, $description, $required=false, $default=null)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']