[TASK] Move classAliasMaps into compatibility6 extension part 6
[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 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 select box, that can be used to switch between
25 * multiple actions and controllers and looks similar to TYPO3s funcMenu.
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 ActionMenuViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper implements \TYPO3\CMS\Fluid\Core\ViewHelper\Facets\ChildNodeAccessInterface {
52
53 /**
54 * @var string
55 */
56 protected $tagName = 'select';
57
58 /**
59 * An array of \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\AbstractNode
60 *
61 * @var array
62 */
63 protected $childNodes = array();
64
65 /**
66 * Setter for ChildNodes - as defined in ChildNodeAccessInterface
67 *
68 * @param array $childNodes Child nodes of this syntax tree node
69 * @return void
70 * @api
71 */
72 public function setChildNodes(array $childNodes) {
73 $this->childNodes = $childNodes;
74 }
75
76 /**
77 * Render FunctionMenu
78 *
79 * @param string $defaultController
80 * @return string
81 */
82 public function render($defaultController = NULL) {
83 $this->tag->addAttribute('onchange', 'jumpToUrl(this.options[this.selectedIndex].value, this);');
84 $options = '';
85 foreach ($this->childNodes as $childNode) {
86 if ($childNode instanceof \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ViewHelperNode) {
87 $options .= $childNode->evaluate($this->renderingContext);
88 }
89 }
90 $this->tag->setContent($options);
91 return '<div class="docheader-funcmenu">' . $this->tag->render() . '</div>';
92 }
93 }