[TASK][WIP] Move non class code back to source files
[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 * View helper which returns a select box, that can be used to switch between
23 * multiple actions and controllers and looks similar to TYPO3s funcMenu.
24 * Note: This view helper is experimental!
25 *
26 * = Examples =
27 *
28 * <code title="Simple">
29 * <f:be.menus.actionMenu>
30 * <f:be.menus.actionMenuItem label="Overview" controller="Blog" action="index" />
31 * <f:be.menus.actionMenuItem label="Create new Blog" controller="Blog" action="new" />
32 * <f:be.menus.actionMenuItem label="List Posts" controller="Post" action="index" arguments="{blog: blog}" />
33 * </f:be.menus.actionMenu>
34 * </code>
35 * <output>
36 * Selectbox with the options "Overview", "Create new Blog" and "List Posts"
37 * </output>
38 *
39 * <code title="Localized">
40 * <f:be.menus.actionMenu>
41 * <f:be.menus.actionMenuItem label="{f:translate(key='overview')}" controller="Blog" action="index" />
42 * <f:be.menus.actionMenuItem label="{f:translate(key='create_blog')}" controller="Blog" action="new" />
43 * </f:be.menus.actionMenu>
44 * </code>
45 * <output>
46 * localized selectbox
47 * <output>
48 */
49 class Tx_Fluid_ViewHelpers_Be_Menus_ActionMenuViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractTagBasedViewHelper implements Tx_Fluid_Core_ViewHelper_Facets_ChildNodeAccessInterface {
50
51 /**
52 * @var string
53 */
54 protected $tagName = 'select';
55
56 /**
57 * An array of Tx_Fluid_Core_Parser_SyntaxTree_AbstractNode
58 *
59 * @var array
60 */
61 protected $childNodes = array();
62
63 /**
64 * Setter for ChildNodes - as defined in ChildNodeAccessInterface
65 *
66 * @param array $childNodes Child nodes of this syntax tree node
67 * @return void
68 * @api
69 */
70 public function setChildNodes(array $childNodes) {
71 $this->childNodes = $childNodes;
72 }
73
74 /**
75 * Render FunctionMenu
76 *
77 * @param string $defaultController
78 * @return string
79 */
80 public function render($defaultController = NULL) {
81 $this->tag->addAttribute('onchange', 'jumpToUrl(this.options[this.selectedIndex].value, this);');
82 $options = '';
83 foreach ($this->childNodes as $childNode) {
84 if ($childNode instanceof Tx_Fluid_Core_Parser_SyntaxTree_ViewHelperNode) {
85 $options .= $childNode->evaluate($this->renderingContext);
86 }
87 }
88 $this->tag->setContent($options);
89 return ('<div class="docheader-funcmenu">' . $this->tag->render()) . '</div>';
90 }
91
92 }
93
94 ?>