[TASK] Streamline phpdoc annotations in EXT:fluid
[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 * View helper which returns a select box, that can be used to switch between
23 * multiple actions and controllers and looks similar to TYPO3s funcMenu.
24 * Note: This view helper is experimental!
25 *
26 * = Examples =
27 *
28 * <code title="Simple">
29 * <f:be.menus.actionMenu>
30 * <f:be.menus.actionMenuItem label="Overview" controller="Blog" action="index" />
31 * <f:be.menus.actionMenuItem label="Create new Blog" controller="Blog" action="new" />
32 * <f:be.menus.actionMenuItem label="List Posts" controller="Post" action="index" arguments="{blog: blog}" />
33 * </f:be.menus.actionMenu>
34 * </code>
35 * <output>
36 * Selectbox with the options "Overview", "Create new Blog" and "List Posts"
37 * </output>
38 *
39 * <code title="Localized">
40 * <f:be.menus.actionMenu>
41 * <f:be.menus.actionMenuItem label="{f:translate(key:'overview')}" controller="Blog" action="index" />
42 * <f:be.menus.actionMenuItem label="{f:translate(key:'create_blog')}" controller="Blog" action="new" />
43 * </f:be.menus.actionMenu>
44 * </code>
45 * <output>
46 * localized selectbox
47 * <output>
48 */
49 class ActionMenuViewHelper extends AbstractTagBasedViewHelper
50 {
51 /**
52 * @var string
53 */
54 protected $tagName = 'select';
55
56 /**
57 * An array of \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\AbstractNode
58 *
59 * @var array
60 */
61 protected $childNodes = [];
62
63 /**
64 * Initialize arguments.
65 *
66 * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception
67 */
68 public function initializeArguments()
69 {
70 parent::initializeArguments();
71 $this->registerArgument('defaultController', 'string', 'defaultController');
72 }
73
74 /**
75 * Render FunctionMenu
76 *
77 * @return string
78 */
79 public function render()
80 {
81 $this->tag->addAttribute('onchange', 'jumpToUrl(this.options[this.selectedIndex].value, this);');
82 $options = '';
83 foreach ($this->childNodes as $childNode) {
84 if ($childNode instanceof \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ViewHelperNode) {
85 $options .= $childNode->evaluate($this->renderingContext);
86 }
87 }
88 $this->tag->setContent($options);
89 return '<div class="docheader-funcmenu">' . $this->tag->render() . '</div>';
90 }
91
92 /**
93 * @param string $argumentsName
94 * @param string $closureName
95 * @param string $initializationPhpCode
96 * @param ViewHelperNode $node
97 * @param TemplateCompiler $compiler
98 */
99 public function compile($argumentsName, $closureName, &$initializationPhpCode, ViewHelperNode $node, TemplateCompiler $compiler)
100 {
101 // @TODO: replace with a true compiling method to make compilable!
102 $compiler->disable();
103 return null;
104 }
105 }