‪TYPO3CMS  9.5
RenderChildrenViewHelper.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
17 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
18 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
19 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
20 
28 class ‪RenderChildrenViewHelper extends AbstractViewHelper
29 {
30  use CompileWithRenderStatic;
31 
37  protected ‪$escapeOutput = false;
38 
42  public function ‪initializeArguments()
43  {
44  $this->registerArgument('arguments', 'array', 'Arguments to assign as template variables', false, []);
45  }
46 
53  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
54  {
55  $subRenderingContext = static::getWidgetRenderingContext($renderingContext);
56  $widgetChildNodes = static::getWidgetChildNodes($renderingContext);
57  static::addArgumentsToTemplateVariableContainer($subRenderingContext, $arguments['arguments']);
58  ‪$output = $widgetChildNodes->evaluate($subRenderingContext);
59  static::removeArgumentsFromTemplateVariableContainer($subRenderingContext, $arguments['arguments']);
60  return ‪$output;
61  }
62 
70  protected static function ‪getWidgetRenderingContext(RenderingContextInterface $renderingContext)
71  {
72  $subRenderingContext = static::getWidgetContext($renderingContext)->getViewHelperChildNodeRenderingContext();
73  if (!$subRenderingContext instanceof \‪TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface) {
74  throw new \TYPO3\CMS\Fluid\Core\Widget\Exception\RenderingContextNotFoundException('Rendering Context not found inside Widget. <f:renderChildren> has been used in an AJAX Request, but is only usable in non-ajax mode.', 1284986604);
75  }
76  return $subRenderingContext;
77  }
78 
83  protected static function ‪getWidgetChildNodes(RenderingContextInterface $renderingContext)
84  {
85  return static::getWidgetContext($renderingContext)->getViewHelperChildNodes();
86  }
87 
93  protected static function ‪getWidgetContext(RenderingContextInterface $renderingContext)
94  {
95  $request = $renderingContext->getControllerContext()->getRequest();
96  if (!$request instanceof \‪TYPO3\CMS\Fluid\Core\Widget\WidgetRequest) {
97  throw new \TYPO3\CMS\Fluid\Core\Widget\Exception\WidgetRequestNotFoundException('The Request is not a WidgetRequest! <f:renderChildren> must be called inside a Widget Template.', 1284986120);
98  }
99  return $request->getWidgetContext();
100  }
101 
108  protected static function ‪addArgumentsToTemplateVariableContainer(RenderingContextInterface $renderingContext, array $arguments)
109  {
110  $templateVariableContainer = $renderingContext->getVariableProvider();
111  foreach ($arguments as $identifier => $value) {
112  $templateVariableContainer->add($identifier, $value);
113  }
114  }
115 
122  protected static function ‪removeArgumentsFromTemplateVariableContainer(RenderingContextInterface $renderingContext, array $arguments)
123  {
124  $templateVariableContainer = $renderingContext->getVariableProvider();
125  foreach ($arguments as $identifier => $value) {
126  $templateVariableContainer->remove($identifier);
127  }
128  }
129 }
‪TYPO3Fluid
‪TYPO3
‪TYPO3\CMS\Fluid\ViewHelpers\RenderChildrenViewHelper\$escapeOutput
‪bool $escapeOutput
Definition: RenderChildrenViewHelper.php:35
‪TYPO3\CMS\Fluid\ViewHelpers\RenderChildrenViewHelper\addArgumentsToTemplateVariableContainer
‪static addArgumentsToTemplateVariableContainer(RenderingContextInterface $renderingContext, array $arguments)
Definition: RenderChildrenViewHelper.php:106
‪TYPO3\CMS\Fluid\ViewHelpers\RenderChildrenViewHelper\getWidgetContext
‪static TYPO3 CMS Fluid Core Widget WidgetContext getWidgetContext(RenderingContextInterface $renderingContext)
Definition: RenderChildrenViewHelper.php:91
‪TYPO3\CMS\Fluid\ViewHelpers\RenderChildrenViewHelper\getWidgetChildNodes
‪static TYPO3Fluid Fluid Core Parser SyntaxTree RootNode getWidgetChildNodes(RenderingContextInterface $renderingContext)
Definition: RenderChildrenViewHelper.php:81
‪TYPO3\CMS\Fluid\ViewHelpers\RenderChildrenViewHelper\getWidgetRenderingContext
‪static TYPO3Fluid Fluid Core Rendering RenderingContextInterface getWidgetRenderingContext(RenderingContextInterface $renderingContext)
Definition: RenderChildrenViewHelper.php:68
‪TYPO3\CMS\Fluid\ViewHelpers\RenderChildrenViewHelper\initializeArguments
‪initializeArguments()
Definition: RenderChildrenViewHelper.php:40
‪TYPO3\CMS\Fluid\ViewHelpers
Definition: BaseViewHelper.php:2
‪$output
‪$output
Definition: annotationChecker.php:113
‪TYPO3\CMS\Fluid\ViewHelpers\RenderChildrenViewHelper
Definition: RenderChildrenViewHelper.php:29
‪TYPO3\CMS\Fluid\ViewHelpers\RenderChildrenViewHelper\removeArgumentsFromTemplateVariableContainer
‪static removeArgumentsFromTemplateVariableContainer(RenderingContextInterface $renderingContext, array $arguments)
Definition: RenderChildrenViewHelper.php:120
‪TYPO3\CMS\Fluid\ViewHelpers\RenderChildrenViewHelper\renderStatic
‪static mixed renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: RenderChildrenViewHelper.php:51