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