[!!!][FEATURE] Compilation of Fluid templates to PHP files
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Be / Menus / ActionMenuViewHelper.php
1 <?php
2 /* *
3 * This script belongs to the FLOW3 package "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 as published by the *
7 * Free Software Foundation, either version 3 of the License, or (at your *
8 * option) any later version. *
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 * @author Steffen Kamper <info@sk-typo3.de>
51 * @author Bastian Waidelich <bastian@typo3.org>
52 * @license http://www.gnu.org/copyleft/gpl.html
53 */
54 class Tx_Fluid_ViewHelpers_Be_Menus_ActionMenuViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractTagBasedViewHelper implements Tx_Fluid_Core_ViewHelper_Facets_ChildNodeAccessInterface {
55
56 /**
57 * @var string
58 */
59 protected $tagName = 'select';
60
61 /**
62 * An array of Tx_Fluid_Core_Parser_SyntaxTree_AbstractNode
63 * @var array
64 */
65 protected $childNodes = array();
66
67 /**
68 * Setter for ChildNodes - as defined in ChildNodeAccessInterface
69 *
70 * @param array $childNodes Child nodes of this syntax tree node
71 * @return void
72 * @author Sebastian Kurf├╝rst <sebastian@typo3.org>
73 * @api
74 */
75 public function setChildNodes(array $childNodes) {
76 $this->childNodes = $childNodes;
77 }
78
79 /**
80 * Render FunctionMenu
81 *
82 * @param string $defaultController
83 * @return string
84 */
85 public function render($defaultController = NULL) {
86 $this->tag->addAttribute('onchange', 'jumpToUrl(this.options[this.selectedIndex].value, this);');
87 $options = '';
88 foreach ($this->childNodes as $childNode) {
89 if ($childNode instanceof Tx_Fluid_Core_Parser_SyntaxTree_ViewHelperNode) {
90 $options .= $childNode->evaluate($this->renderingContext);
91 }
92 }
93 $this->tag->setContent($options);
94 return '<div class="docheader-funcmenu">' . $this->tag->render() . '</div>';
95 }
96 }
97 ?>