Revert "[TASK] Make \Be\Menus\ActionMenuItemViewHelper compilable"
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Be / Menus / ActionMenuItemViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Be\Menus;
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 * */
23 /**
24 * View helper which returns a option tag.
25 * This view helper only works in conjunction with \TYPO3\CMS\Fluid\ViewHelpers\Be\Menus\ActionMenuViewHelper
26 * Note: This view helper is experimental!
27 *
28 * = Examples =
29 *
30 * <code title="Simple">
31 * <f:be.menus.actionMenu>
32 * <f:be.menus.actionMenuItem label="Overview" controller="Blog" action="index" />
33 * <f:be.menus.actionMenuItem label="Create new Blog" controller="Blog" action="new" />
34 * <f:be.menus.actionMenuItem label="List Posts" controller="Post" action="index" arguments="{blog: blog}" />
35 * </f:be.menus.actionMenu>
36 * </code>
37 * <output>
38 * Selectbox with the options "Overview", "Create new Blog" and "List Posts"
39 * </output>
40 *
41 * <code title="Localized">
42 * <f:be.menus.actionMenu>
43 * <f:be.menus.actionMenuItem label="{f:translate(key='overview')}" controller="Blog" action="index" />
44 * <f:be.menus.actionMenuItem label="{f:translate(key='create_blog')}" controller="Blog" action="new" />
45 * </f:be.menus.actionMenu>
46 * </code>
47 * <output>
48 * localized selectbox
49 * <output>
50 */
51 class ActionMenuItemViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper {
52
53 /**
54 * @var string
55 */
56 protected $tagName = 'option';
57
58 /**
59 * Renders an ActionMenu option tag
60 *
61 * @param string $label label of the option tag
62 * @param string $controller controller to be associated with this ActionMenuItem
63 * @param string $action the action to be associated with this ActionMenuItem
64 * @param array $arguments additional controller arguments to be passed to the action when this ActionMenuItem is selected
65 * @return string the rendered option tag
66 * @see \TYPO3\CMS\Fluid\ViewHelpers\Be\Menus\ActionMenuViewHelper
67 */
68 public function render($label, $controller, $action, array $arguments = array()) {
69 $uriBuilder = $this->controllerContext->getUriBuilder();
70 $uri = $uriBuilder->reset()->uriFor($action, $arguments, $controller);
71 $this->tag->addAttribute('value', $uri);
72 $currentRequest = $this->controllerContext->getRequest();
73 $currentController = $currentRequest->getControllerName();
74 $currentAction = $currentRequest->getControllerActionName();
75 if ($action === $currentAction && $controller === $currentController) {
76 $this->tag->addAttribute('selected', 'selected');
77 }
78 $this->tag->setContent($label);
79 return $this->tag->render();
80 }
81
82 }