[+BUGFIX] Fluid: Replaced SplObjectStorage by Tx_Extbase_Persistence_ObjectStorage...
[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 *
37 * Output:
38 * Selectbox with the options "Overview", "Create new Blog" and "List Posts"
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 *
47 * @author Steffen Kamper <info@sk-typo3.de>
48 * @author Bastian Waidelich <bastian@typo3.org>
49 * @license http://www.gnu.org/copyleft/gpl.html
50 * @version SVN: $Id:
51 *
52 */
53 class Tx_Fluid_ViewHelpers_Be_Menus_ActionMenuViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractTagBasedViewHelper implements Tx_Fluid_Core_ViewHelper_Facets_ChildNodeAccessInterface {
54
55 /**
56 * @var string
57 */
58 protected $tagName = 'select';
59
60 /**
61 * An array of Tx_Fluid_Core_Parser_SyntaxTree_AbstractNode
62 * @var array
63 */
64 protected $childNodes = array();
65
66 /**
67 * Setter for ChildNodes - as defined in ChildNodeAccessInterface
68 *
69 * @param array $childNodes Child nodes of this syntax tree node
70 * @return void
71 * @author Sebastian Kurf├╝rst <sebastian@typo3.org>
72 * @api
73 */
74 public function setChildNodes(array $childNodes) {
75 $this->childNodes = $childNodes;
76 }
77
78 /**
79 * Render FunctionMenu
80 *
81 * @param string $defaultController
82 * @return string
83 */
84 public function render($defaultController = NULL) {
85 $this->tag->addAttribute('onchange', 'jumpToUrl(this.options[this.selectedIndex].value, this);');
86 $options = '';
87 foreach ($this->childNodes as $childNode) {
88 if ($childNode instanceof Tx_Fluid_Core_Parser_SyntaxTree_ViewHelperNode) {
89 $options .= $childNode->evaluate($this->getRenderingContext());
90 }
91 }
92 $this->tag->setContent($options);
93 return '<div class="docheader-funcmenu">' . $this->tag->render() . '</div>';
94 }
95 }
96 ?>