Merge "[TASK] Increase version number"
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Be / Menus / ActionMenuViewHelper.php
1 <?php
2 /* *
3 * This script is backported from the FLOW3 package "TYPO3.Fluid". *
4 * *
5 * It is free software; you can redistribute it and/or modify it under *
6 * the terms of the GNU Lesser General Public License, either version 3 *
7 * of the License, or (at your option) any later version. *
8 * *
9 * *
10 * This script is distributed in the hope that it will be useful, but *
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
12 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
13 * General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU Lesser General Public *
16 * License along with the script. *
17 * If not, see http://www.gnu.org/licenses/lgpl.html *
18 * *
19 * The TYPO3 project - inspiring people to share! *
20 * */
21
22 /**
23 * View helper which returns a select box, that can be used to switch between
24 * multiple actions and controllers and looks similar to TYPO3s funcMenu.
25 * Note: This view helper is experimental!
26 *
27 * = Examples =
28 *
29 * <code title="Simple">
30 * <f:be.menus.actionMenu>
31 * <f:be.menus.actionMenuItem label="Overview" controller="Blog" action="index" />
32 * <f:be.menus.actionMenuItem label="Create new Blog" controller="Blog" action="new" />
33 * <f:be.menus.actionMenuItem label="List Posts" controller="Post" action="index" arguments="{blog: blog}" />
34 * </f:be.menus.actionMenu>
35 * </code>
36 * <output>
37 * Selectbox with the options "Overview", "Create new Blog" and "List Posts"
38 * </output>
39 *
40 * <code title="Localized">
41 * <f:be.menus.actionMenu>
42 * <f:be.menus.actionMenuItem label="{f:translate(key='overview')}" controller="Blog" action="index" />
43 * <f:be.menus.actionMenuItem label="{f:translate(key='create_blog')}" controller="Blog" action="new" />
44 * </f:be.menus.actionMenu>
45 * </code>
46 * <output>
47 * localized selectbox
48 * <output>
49 *
50 */
51 class Tx_Fluid_ViewHelpers_Be_Menus_ActionMenuViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractTagBasedViewHelper implements Tx_Fluid_Core_ViewHelper_Facets_ChildNodeAccessInterface {
52
53 /**
54 * @var string
55 */
56 protected $tagName = 'select';
57
58 /**
59 * An array of Tx_Fluid_Core_Parser_SyntaxTree_AbstractNode
60 * @var array
61 */
62 protected $childNodes = array();
63
64 /**
65 * Setter for ChildNodes - as defined in ChildNodeAccessInterface
66 *
67 * @param array $childNodes Child nodes of this syntax tree node
68 * @return void
69 * @api
70 */
71 public function setChildNodes(array $childNodes) {
72 $this->childNodes = $childNodes;
73 }
74
75 /**
76 * Render FunctionMenu
77 *
78 * @param string $defaultController
79 * @return string
80 */
81 public function render($defaultController = NULL) {
82 $this->tag->addAttribute('onchange', 'jumpToUrl(this.options[this.selectedIndex].value, this);');
83 $options = '';
84 foreach ($this->childNodes as $childNode) {
85 if ($childNode instanceof Tx_Fluid_Core_Parser_SyntaxTree_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 ?>