‪TYPO3CMS  10.4
RenderChildrenViewHelper.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
21 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
22 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
23 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
24 
32 class ‪RenderChildrenViewHelper extends AbstractViewHelper
33 {
34  use CompileWithRenderStatic;
35 
41  protected ‪$escapeOutput = false;
42 
46  public function ‪initializeArguments()
47  {
48  $this->registerArgument('arguments', 'array', 'Arguments to assign as template variables', false, []);
49  }
50 
57  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
58  {
59  $subRenderingContext = static::getWidgetRenderingContext($renderingContext);
60  $widgetChildNodes = static::getWidgetChildNodes($renderingContext);
61  static::addArgumentsToTemplateVariableContainer($subRenderingContext, $arguments['arguments']);
62  ‪$output = $widgetChildNodes->evaluate($subRenderingContext);
63  static::removeArgumentsFromTemplateVariableContainer($subRenderingContext, $arguments['arguments']);
64  return ‪$output;
65  }
66 
74  protected static function ‪getWidgetRenderingContext(RenderingContextInterface $renderingContext)
75  {
76  $subRenderingContext = static::getWidgetContext($renderingContext)->getViewHelperChildNodeRenderingContext();
77  if (!$subRenderingContext instanceof RenderingContextInterface) {
78  throw new ‪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);
79  }
80  return $subRenderingContext;
81  }
82 
87  protected static function ‪getWidgetChildNodes(RenderingContextInterface $renderingContext)
88  {
89  return static::getWidgetContext($renderingContext)->getViewHelperChildNodes();
90  }
91 
97  protected static function ‪getWidgetContext(RenderingContextInterface $renderingContext)
98  {
99  $request = $renderingContext->getControllerContext()->getRequest();
100  if (!$request instanceof ‪WidgetRequest) {
101  throw new ‪WidgetRequestNotFoundException('The Request is not a WidgetRequest! <f:renderChildren> must be called inside a Widget Template.', 1284986120);
102  }
103  return $request->getWidgetContext();
104  }
105 
112  protected static function ‪addArgumentsToTemplateVariableContainer(RenderingContextInterface $renderingContext, array $arguments)
113  {
114  $templateVariableContainer = $renderingContext->getVariableProvider();
115  foreach ($arguments as $identifier => $value) {
116  $templateVariableContainer->add($identifier, $value);
117  }
118  }
119 
126  protected static function ‪removeArgumentsFromTemplateVariableContainer(RenderingContextInterface $renderingContext, array $arguments)
127  {
128  $templateVariableContainer = $renderingContext->getVariableProvider();
129  foreach ($arguments as $identifier => $value) {
130  $templateVariableContainer->remove($identifier);
131  }
132  }
133 }
‪TYPO3\CMS\Fluid\Core\Widget\WidgetRequest
Definition: WidgetRequest.php:25
‪TYPO3\CMS\Fluid\ViewHelpers\RenderChildrenViewHelper\$escapeOutput
‪bool $escapeOutput
Definition: RenderChildrenViewHelper.php:39
‪TYPO3\CMS\Fluid\ViewHelpers\RenderChildrenViewHelper\addArgumentsToTemplateVariableContainer
‪static addArgumentsToTemplateVariableContainer(RenderingContextInterface $renderingContext, array $arguments)
Definition: RenderChildrenViewHelper.php:110
‪TYPO3\CMS\Fluid\Core\Widget\Exception\RenderingContextNotFoundException
Definition: RenderingContextNotFoundException.php:26
‪TYPO3\CMS\Fluid\ViewHelpers\RenderChildrenViewHelper\getWidgetContext
‪static TYPO3 CMS Fluid Core Widget WidgetContext getWidgetContext(RenderingContextInterface $renderingContext)
Definition: RenderChildrenViewHelper.php:95
‪TYPO3\CMS\Fluid\ViewHelpers\RenderChildrenViewHelper\getWidgetChildNodes
‪static TYPO3Fluid Fluid Core Parser SyntaxTree RootNode getWidgetChildNodes(RenderingContextInterface $renderingContext)
Definition: RenderChildrenViewHelper.php:85
‪TYPO3\CMS\Fluid\ViewHelpers\RenderChildrenViewHelper\getWidgetRenderingContext
‪static TYPO3Fluid Fluid Core Rendering RenderingContextInterface getWidgetRenderingContext(RenderingContextInterface $renderingContext)
Definition: RenderChildrenViewHelper.php:72
‪TYPO3\CMS\Fluid\Core\Widget\Exception\WidgetRequestNotFoundException
Definition: WidgetRequestNotFoundException.php:26
‪TYPO3\CMS\Fluid\ViewHelpers\RenderChildrenViewHelper\initializeArguments
‪initializeArguments()
Definition: RenderChildrenViewHelper.php:44
‪TYPO3\CMS\Fluid\ViewHelpers
‪$output
‪$output
Definition: annotationChecker.php:119
‪TYPO3\CMS\Fluid\ViewHelpers\RenderChildrenViewHelper
Definition: RenderChildrenViewHelper.php:33
‪TYPO3\CMS\Fluid\ViewHelpers\RenderChildrenViewHelper\removeArgumentsFromTemplateVariableContainer
‪static removeArgumentsFromTemplateVariableContainer(RenderingContextInterface $renderingContext, array $arguments)
Definition: RenderChildrenViewHelper.php:124
‪TYPO3\CMS\Fluid\ViewHelpers\RenderChildrenViewHelper\renderStatic
‪static mixed renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: RenderChildrenViewHelper.php:55