492fe42f70f88c9436d7d89c489b89c79b72f208
[Packages/TYPO3.CMS.git] / typo3 / sysext / reports / Classes / ViewHelpers / ActionMenuItemViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Reports\ViewHelpers;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012-2013 Georg Ringer <typo3@ringerge.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26 /**
27 * Render an item of the menu
28 *
29 */
30 class ActionMenuItemViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper {
31
32 /**
33 * @var string
34 */
35 protected $tagName = 'option';
36
37 /**
38 * Renders an ActionMenu option tag
39 *
40 * @param string $label label of the option tag
41 * @param string $controller controller to be associated with this ActionMenuItem
42 * @param string $action the action to be associated with this ActionMenuItem
43 * @param array $arguments additional controller arguments to be passed to the action when this ActionMenuItem is selected
44 * @return string the rendered option tag
45 * @see Tx_Fluid_ViewHelpers_Be_Menus_ActionMenuViewHelper
46 */
47 public function render($label, $controller, $action, array $arguments = array()) {
48 $uriBuilder = $this->controllerContext->getUriBuilder();
49 $uri = $uriBuilder->reset()->uriFor($action, $arguments, $controller);
50 $this->tag->addAttribute('value', $uri);
51 $currentRequest = $this->controllerContext->getRequest();
52 $currentController = $currentRequest->getControllerName();
53 $currentAction = $currentRequest->getControllerActionName();
54 $currentArguments = $currentRequest->getArguments();
55 unset($currentArguments['action']);
56 unset($currentArguments['controller']);
57 unset($currentArguments['redirect']);
58
59 if ($action === $currentAction && $controller === $currentController && $currentArguments === $arguments) {
60 $this->tag->addAttribute('selected', 'selected');
61 }
62 $this->tag->setContent($label);
63 return $this->tag->render();
64 }
65
66 }