TYPO3 CMS  TYPO3_8-7
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 
27 {
33  protected $escapeOutput = false;
34 
38  public function initializeArguments()
39  {
40  parent::initializeArguments();
41  $this->registerArgument('arguments', 'array', 'Arguments to assign as template variables', false, []);
42  }
43 
47  public function render()
48  {
49  $renderingContext = $this->getWidgetRenderingContext();
50  $widgetChildNodes = $this->getWidgetChildNodes();
51  $this->addArgumentsToTemplateVariableContainer($this->arguments['arguments']);
52  $output = $widgetChildNodes->evaluate($renderingContext);
53  $this->removeArgumentsFromTemplateVariableContainer($this->arguments['arguments']);
54  return $output;
55  }
56 
63  protected function getWidgetRenderingContext()
64  {
65  $renderingContext = $this->getWidgetContext()->getViewHelperChildNodeRenderingContext();
66  if (!$renderingContext instanceof \TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface) {
67  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);
68  }
69  return $renderingContext;
70  }
71 
75  protected function getWidgetChildNodes()
76  {
77  return $this->getWidgetContext()->getViewHelperChildNodes();
78  }
79 
84  protected function getWidgetContext()
85  {
86  $request = $this->controllerContext->getRequest();
87  if (!$request instanceof \TYPO3\CMS\Fluid\Core\Widget\WidgetRequest) {
88  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);
89  }
90  return $request->getWidgetContext();
91  }
92 
98  protected function addArgumentsToTemplateVariableContainer(array $arguments)
99  {
100  $templateVariableContainer = $this->getWidgetRenderingContext()->getVariableProvider();
101  foreach ($arguments as $identifier => $value) {
102  $templateVariableContainer->add($identifier, $value);
103  }
104  }
105 
111  protected function removeArgumentsFromTemplateVariableContainer(array $arguments)
112  {
113  $templateVariableContainer = $this->getWidgetRenderingContext()->getVariableProvider();
114  foreach ($arguments as $identifier => $value) {
115  $templateVariableContainer->remove($identifier);
116  }
117  }
118 }