EXTMVC:
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / View / Helper / TX_EXTMVC_View_Helper_LinkHelper.php
1 <?php
2
3 /* *
4 * This script belongs to the FLOW3 framework. *
5 * *
6 * It is free software; you can redistribute it and/or modify it under *
7 * the terms of the GNU Lesser General Public License as published by the *
8 * Free Software Foundation, either version 3 of the License, or (at your *
9 * option) any later version. *
10 * *
11 * This script is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
13 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
14 * General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with the script. *
18 * If not, see http://www.gnu.org/licenses/lgpl.html *
19 * *
20 * The TYPO3 project - inspiring people to share! *
21 * */
22
23 require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/View/Helper/TX_EXTMVC_View_Helper_AbstractHelper.php');
24
25 /**
26 * A For Helper
27 *
28 * @version $Id:$
29 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
30 */
31 class TX_EXTMVC_View_Helper_LinkHelper extends TX_EXTMVC_View_Helper_AbstractHelper {
32
33 /**
34 * an instance of tslib_cObj
35 *
36 * @var tslib_cObj
37 */
38 protected $contentObject = null;
39
40 /**
41 * constructor for class tx_community_viewhelper_Link
42 */
43 public function __construct(array $arguments = array()) {
44 if (is_null($this->contentObject)) {
45 $this->contentObject = t3lib_div::makeInstance('tslib_cObj');
46 }
47 }
48
49 public function render($view, $content, $arguments, $templateResource, $variables) {
50 $parameters = t3lib_div::_GET();
51 $prefixedExtensionKey = 'tx_' . $this->request->getControllerExtensionKey();
52 if (!empty($arguments['to'])) {
53 $linkTo = $arguments['to'];
54 $view->replaceReferencesWithValues($linkTo, $variables);
55 unset($parameters['id']);
56 }
57 if (!empty($arguments['parameters'])) {
58 $explodedParameters = explode(' ', $arguments['parameters']);
59 $additionalParameters = array();
60 foreach ($explodedParameters as $parameterString) {
61 list($parameterKey, $parameterValue) = explode('=', trim($parameterString));
62 $view->replaceReferencesWithValues($parameterValue, $variables);
63 $additionalParameters[$prefixedExtensionKey] = array(trim($parameterKey) => $parameterValue);
64 if (is_array($parameters[$prefixedExtensionKey])) {
65 $parameters[$prefixedExtensionKey] = array_merge($parameters[$prefixedExtensionKey], $additionalParameters[$prefixedExtensionKey]);
66 } else {
67 $parameters[$prefixedExtensionKey] = $additionalParameters[$prefixedExtensionKey];
68 }
69 }
70 }
71
72 $linkText = $view->renderTemplate($templateResource, $variables);
73
74 $parameters = is_array($parameters) ? t3lib_div::implodeArrayForUrl('', $parameters, '', 1) : '';
75
76 $link = $this->contentObject->typoLink(
77 $linkText,
78 array(
79 'parameter' => $linkTo, // FIXME
80 'additionalParams' => $parameters
81 )
82 );
83
84 return $link;
85 }
86
87 }
88
89 ?>