[TASK] Improve visual appearance of feature toggles
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Be / Menus / ActionMenuViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Be\Menus;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3Fluid\Fluid\Core\Compiler\TemplateCompiler;
18 use TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\ViewHelperNode;
19 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
20
21 /**
22 * ViewHelper which returns a select box, that can be used to switch between
23 * multiple actions and controllers and looks similar to TYPO3s funcMenu.
24 *
25 * .. note::
26 * This ViewHelper is experimental!
27 *
28 * Examples
29 * ========
30 *
31 * Simple::
32 *
33 * <f:be.menus.actionMenu>
34 * <f:be.menus.actionMenuItem label="Overview" controller="Blog" action="index" />
35 * <f:be.menus.actionMenuItem label="Create new Blog" controller="Blog" action="new" />
36 * <f:be.menus.actionMenuItem label="List Posts" controller="Post" action="index" arguments="{blog: blog}" />
37 * </f:be.menus.actionMenu>
38 *
39 * Selectbox with the options "Overview", "Create new Blog" and "List Posts".
40 *
41 * Localized::
42 *
43 * <f:be.menus.actionMenu>
44 * <f:be.menus.actionMenuItem label="{f:translate(key:'overview')}" controller="Blog" action="index" />
45 * <f:be.menus.actionMenuItem label="{f:translate(key:'create_blog')}" controller="Blog" action="new" />
46 * </f:be.menus.actionMenu>
47 *
48 * Localized selectbox.
49 */
50 class ActionMenuViewHelper extends AbstractTagBasedViewHelper
51 {
52 /**
53 * @var string
54 */
55 protected $tagName = 'select';
56
57 /**
58 * An array of \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\AbstractNode
59 *
60 * @var array
61 */
62 protected $childNodes = [];
63
64 /**
65 * Initialize arguments.
66 *
67 * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception
68 */
69 public function initializeArguments()
70 {
71 parent::initializeArguments();
72 $this->registerArgument('defaultController', 'string', 'defaultController');
73 }
74
75 /**
76 * Render FunctionMenu
77 *
78 * @return string
79 */
80 public function render()
81 {
82 $this->tag->addAttribute('onchange', 'window.location.href = this.options[this.selectedIndex].value;');
83 $options = '';
84 foreach ($this->childNodes as $childNode) {
85 if ($childNode instanceof ViewHelperNode) {
86 $options .= $childNode->evaluate($this->renderingContext);
87 }
88 }
89 $this->tag->setContent($options);
90 return '<div class="docheader-funcmenu">' . $this->tag->render() . '</div>';
91 }
92
93 /**
94 * @param string $argumentsName
95 * @param string $closureName
96 * @param string $initializationPhpCode
97 * @param ViewHelperNode $node
98 * @param TemplateCompiler $compiler
99 */
100 public function compile($argumentsName, $closureName, &$initializationPhpCode, ViewHelperNode $node, TemplateCompiler $compiler)
101 {
102 // @TODO: replace with a true compiling method to make compilable!
103 $compiler->disable();
104 return null;
105 }
106 }