‪TYPO3CMS  10.4
FluidFormRenderer.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
18 /*
19  * Inspired by and partially taken from the Neos.Form package (www.neos.io)
20  */
21 
23 
29 
128 {
129 
143  public function ‪render(): string
144  {
145  $formElementType = $this->formRuntime->getType();
146  $renderingOptions = $this->formRuntime->getRenderingOptions();
147 
148  $view = GeneralUtility::makeInstance(ObjectManager::class)
149  ->get(TemplateView::class);
150  $view->setControllerContext($this->controllerContext);
151 
152  if (!isset($renderingOptions['templateRootPaths'])) {
153  throw new ‪RenderingException(
154  sprintf('The option templateRootPaths must be set for renderable "%s"', $formElementType),
155  1480293084
156  );
157  }
158  if (!isset($renderingOptions['layoutRootPaths'])) {
159  throw new ‪RenderingException(
160  sprintf('The option layoutRootPaths must be set for renderable "%s"', $formElementType),
161  1480293085
162  );
163  }
164  if (!isset($renderingOptions['partialRootPaths'])) {
165  throw new ‪RenderingException(
166  sprintf('The option partialRootPaths must be set for renderable "%s"', $formElementType),
167  1480293086
168  );
169  }
170 
171  $view->assign('form', $this->formRuntime);
172 
173  $view->getRenderingContext()
174  ->getViewHelperVariableContainer()
175  ->addOrUpdate(RenderRenderableViewHelper::class, 'formRuntime', $this->formRuntime);
176 
177  // Configure the fluid TemplatePaths with the rendering options
178  // from the renderable
179  $view->getTemplatePaths()->fillFromConfigurationArray($renderingOptions);
180 
181  foreach (‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/form']['beforeRendering'] ?? [] as $className) {
182  $hookObj = GeneralUtility::makeInstance($className);
183  if (method_exists($hookObj, 'beforeRendering')) {
184  $hookObj->beforeRendering(
185  $this->formRuntime,
186  $this->formRuntime->getFormDefinition()
187  );
188  }
189  }
190 
191  return $view->render($this->formRuntime->getTemplateName());
192  }
193 }
‪TYPO3\CMS\Form\Domain\Renderer
Definition: AbstractElementRenderer.php:22
‪TYPO3\CMS\Fluid\View\TemplateView
Definition: TemplateView.php:25
‪TYPO3\CMS\Form\Domain\Renderer\FluidFormRenderer
Definition: FluidFormRenderer.php:128
‪TYPO3\CMS\Form\Domain\Renderer\AbstractElementRenderer
Definition: AbstractElementRenderer.php:34
‪TYPO3\CMS\Form\ViewHelpers\RenderRenderableViewHelper
Definition: RenderRenderableViewHelper.php:41
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Form\Domain\Exception\RenderingException
Definition: RenderingException.php:30
‪TYPO3\CMS\Form\Domain\Renderer\FluidFormRenderer\render
‪string render()
Definition: FluidFormRenderer.php:143
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:28