Merge "[TASK] Increase version number"
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / SectionViewHelper.php
1 <?php
2
3 /* *
4 * This script is backported from the FLOW3 package "TYPO3.Fluid". *
5 * *
6 * It is free software; you can redistribute it and/or modify it under *
7 * the terms of the GNU Lesser General Public License, either version 3 *
8 * of the License, or (at your option) any later version. *
9 * *
10 * The TYPO3 project - inspiring people to share! *
11 * */
12
13
14 /**
15 * A Section view helper
16 *
17 * == Examples ==
18 *
19 * <code title="Rendering sections">
20 * <f:section name="someSection">This is a section. {foo}</f:section>
21 * <f:render section="someSection" arguments="{foo: someVariable}" />
22 * </code>
23 * <output>
24 * the content of the section "someSection". The content of the variable {someVariable} will be available in the partial as {foo}
25 * </output>
26 *
27 * <code title="Rendering recursive sections">
28 * <f:section name="mySection">
29 * <ul>
30 * <f:for each="{myMenu}" as="menuItem">
31 * <li>
32 * {menuItem.text}
33 * <f:if condition="{menuItem.subItems}">
34 * <f:render section="mySection" arguments="{myMenu: menuItem.subItems}" />
35 * </f:if>
36 * </li>
37 * </f:for>
38 * </ul>
39 * </f:section>
40 * <f:render section="mySection" arguments="{myMenu: menu}" />
41 * </code>
42 * <output>
43 * <ul>
44 * <li>menu1
45 * <ul>
46 * <li>menu1a</li>
47 * <li>menu1b</li>
48 * </ul>
49 * </li>
50 * [...]
51 * (depending on the value of {menu})
52 * </output>
53 *
54 * @api
55 */
56 class Tx_Fluid_ViewHelpers_SectionViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractViewHelper implements Tx_Fluid_Core_ViewHelper_Facets_PostParseInterface, Tx_Fluid_Core_ViewHelper_Facets_CompilableInterface {
57
58 /**
59 * Initialize the arguments.
60 *
61 * @return void
62 * @api
63 */
64 public function initializeArguments() {
65 $this->registerArgument('name', 'string', 'Name of the section', TRUE);
66 }
67
68 /**
69 * Save the associated view helper node in a static public class variable.
70 * called directly after the view helper was built.
71 *
72 * @param Tx_Fluid_Core_Parser_SyntaxTree_ViewHelperNode $syntaxTreeNode
73 * @param array $viewHelperArguments
74 * @param Tx_Fluid_Core_ViewHelper_TemplateVariableContainer $variableContainer
75 * @return void
76 */
77 static public function postParseEvent(Tx_Fluid_Core_Parser_SyntaxTree_ViewHelperNode $syntaxTreeNode, array $viewHelperArguments, Tx_Fluid_Core_ViewHelper_TemplateVariableContainer $variableContainer) {
78 $sectionName = $viewHelperArguments['name']->getText();
79 if (!$variableContainer->exists('sections')) {
80 $variableContainer->add('sections', array());
81 }
82 $sections = $variableContainer->get('sections');
83 $sections[$sectionName] = $syntaxTreeNode;
84 $variableContainer->remove('sections');
85 $variableContainer->add('sections', $sections);
86 }
87
88 /**
89 * Rendering directly returns all child nodes.
90 *
91 * @return string HTML String of all child nodes.
92 * @api
93 */
94 public function render() {
95 if ($this->viewHelperVariableContainer->exists('Tx_Fluid_ViewHelpers_SectionViewHelper', 'isCurrentlyRenderingSection')) {
96 $this->viewHelperVariableContainer->remove('Tx_Fluid_ViewHelpers_SectionViewHelper', 'isCurrentlyRenderingSection');
97 return $this->renderChildren();
98 }
99 return '';
100 }
101
102 /**
103 * The inner contents of a section should not be rendered.
104 *
105 * @param string $argumentsVariableName
106 * @param string $renderChildrenClosureVariableName
107 * @param string $initializationPhpCode
108 * @param Tx_Fluid_Core_Parser_SyntaxTree_AbstractNode $syntaxTreeNode
109 * @param Tx_Fluid_Core_Compiler_TemplateCompiler $templateCompiler
110 * @return string
111 */
112 public function compile($argumentsVariableName, $renderChildrenClosureVariableName, &$initializationPhpCode, Tx_Fluid_Core_Parser_SyntaxTree_AbstractNode $syntaxTreeNode, Tx_Fluid_Core_Compiler_TemplateCompiler $templateCompiler) {
113 return '\'\'';
114 }
115 }
116
117 ?>