TYPO3  7.6
LinkViewHelper.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Widget;
3 
4 /* *
5  * This script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6  * *
7  * It is free software; you can redistribute it and/or modify it under *
8  * the terms of the GNU Lesser General Public License, either version 3 *
9  * of the License, or (at your option) any later version. *
10  * *
11  * *
12  * This script is distributed in the hope that it will be useful, but *
13  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
14  * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
15  * General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU Lesser General Public *
18  * License along with the script. *
19  * If not, see http://www.gnu.org/licenses/lgpl.html *
20  * *
21  * The TYPO3 project - inspiring people to share! *
22  * */
39 {
43  protected $tagName = 'a';
44 
51  public function initializeArguments()
52  {
54  $this->registerTagAttribute('name', 'string', 'Specifies the name of an anchor');
55  $this->registerTagAttribute('rel', 'string', 'Specifies the relationship between the current document and the linked document');
56  $this->registerTagAttribute('rev', 'string', 'Specifies the relationship between the linked document and the current document');
57  $this->registerTagAttribute('target', 'string', 'Specifies where to open the linked document');
58  $this->registerArgument('addQueryStringMethod', 'string', 'Method to be used for query string');
59  }
60 
72  public function render($action = null, $arguments = array(), $section = '', $format = '', $ajax = false)
73  {
74  if ($ajax === true) {
75  $uri = $this->getAjaxUri();
76  } else {
77  $uri = $this->getWidgetUri();
78  }
79  $this->tag->addAttribute('href', $uri);
80  $this->tag->setContent($this->renderChildren());
81  return $this->tag->render();
82  }
83 
89  protected function getAjaxUri()
90  {
91  $action = $this->arguments['action'];
92  $arguments = $this->arguments['arguments'];
93  if ($action === null) {
94  $action = $this->controllerContext->getRequest()->getControllerActionName();
95  }
96  $arguments['id'] = $GLOBALS['TSFE']->id;
97  // @todo page type should be configurable
98  $arguments['type'] = 7076;
99  $arguments['fluid-widget-id'] = $this->controllerContext->getRequest()->getWidgetContext()->getAjaxWidgetIdentifier();
100  $arguments['action'] = $action;
101  return '?' . http_build_query($arguments, null, '&');
102  }
103 
109  protected function getWidgetUri()
110  {
111  $uriBuilder = $this->controllerContext->getUriBuilder();
112  $argumentPrefix = $this->controllerContext->getRequest()->getArgumentPrefix();
113  $arguments = $this->hasArgument('arguments') ? $this->arguments['arguments'] : array();
114  if ($this->hasArgument('action')) {
115  $arguments['action'] = $this->arguments['action'];
116  }
117  if ($this->hasArgument('format') && $this->arguments['format'] !== '') {
118  $arguments['format'] = $this->arguments['format'];
119  }
120  if ($this->hasArgument('addQueryStringMethod') && $this->arguments['addQueryStringMethod'] !== '') {
121  $arguments['addQueryStringMethod'] = $this->arguments['addQueryStringMethod'];
122  }
123  return $uriBuilder->reset()->setArguments(array($argumentPrefix => $arguments))->setSection($this->arguments['section'])->setAddQueryString(true)->setAddQueryStringMethod($this->arguments['addQueryStringMethod'])->setArgumentsToBeExcludedFromQueryString(array($argumentPrefix, 'cHash'))->setFormat($this->arguments['format'])->build();
124  }
125 }