[CLEANUP] Rework/simplify copyright header and remove @package
[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 backported from the TYPO3 Flow package "TYPO3.Fluid".
8 *
9 * It is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, either version 2
11 * of the License, or any later version.
12 *
13 * For the full copyright and license information, please read the
14 * LICENSE.txt file that was distributed with this source code.
15 *
16 * The TYPO3 project - inspiring people to share!
17 */
18
19 /**
20 * View helper which returns a select box, that can be used to switch between
21 * multiple actions and controllers and looks similar to TYPO3s funcMenu.
22 * Note: This view helper is experimental!
23 *
24 * = Examples =
25 *
26 * <code title="Simple">
27 * <f:be.menus.actionMenu>
28 * <f:be.menus.actionMenuItem label="Overview" controller="Blog" action="index" />
29 * <f:be.menus.actionMenuItem label="Create new Blog" controller="Blog" action="new" />
30 * <f:be.menus.actionMenuItem label="List Posts" controller="Post" action="index" arguments="{blog: blog}" />
31 * </f:be.menus.actionMenu>
32 * </code>
33 * <output>
34 * Selectbox with the options "Overview", "Create new Blog" and "List Posts"
35 * </output>
36 *
37 * <code title="Localized">
38 * <f:be.menus.actionMenu>
39 * <f:be.menus.actionMenuItem label="{f:translate(key:'overview')}" controller="Blog" action="index" />
40 * <f:be.menus.actionMenuItem label="{f:translate(key:'create_blog')}" controller="Blog" action="new" />
41 * </f:be.menus.actionMenu>
42 * </code>
43 * <output>
44 * localized selectbox
45 * <output>
46 */
47 class ActionMenuViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper implements \TYPO3\CMS\Fluid\Core\ViewHelper\Facets\ChildNodeAccessInterface {
48
49 /**
50 * @var string
51 */
52 protected $tagName = 'select';
53
54 /**
55 * An array of Tx_Fluid_Core_Parser_SyntaxTree_AbstractNode
56 *
57 * @var array
58 */
59 protected $childNodes = array();
60
61 /**
62 * Setter for ChildNodes - as defined in ChildNodeAccessInterface
63 *
64 * @param array $childNodes Child nodes of this syntax tree node
65 * @return void
66 * @api
67 */
68 public function setChildNodes(array $childNodes) {
69 $this->childNodes = $childNodes;
70 }
71
72 /**
73 * Render FunctionMenu
74 *
75 * @param string $defaultController
76 * @return string
77 */
78 public function render($defaultController = NULL) {
79 $this->tag->addAttribute('onchange', 'jumpToUrl(this.options[this.selectedIndex].value, this);');
80 $options = '';
81 foreach ($this->childNodes as $childNode) {
82 if ($childNode instanceof \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ViewHelperNode) {
83 $options .= $childNode->evaluate($this->renderingContext);
84 }
85 }
86 $this->tag->setContent($options);
87 return '<div class="docheader-funcmenu">' . $this->tag->render() . '</div>';
88 }
89 }