TYPO3 CMS  TYPO3_8-7
RenderViewHelper.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It originated from the Neos.Form package (www.neos.io)
9  *
10  * It is free software; you can redistribute it and/or modify it under
11  * the terms of the GNU General Public License, either version 2
12  * of the License, or any later version.
13  *
14  * For the full copyright and license information, please read the
15  * LICENSE.txt file that was distributed with this source code.
16  *
17  * The TYPO3 project - inspiring people to share!
18  */
19 
27 
45 {
47 
51  protected $escapeOutput = false;
52 
58  public function initializeArguments()
59  {
60  parent::initializeArguments();
61  $this->registerArgument('persistenceIdentifier', 'string', 'The persistence identifier for the form.', false, null);
62  $this->registerArgument('factoryClass', 'string', 'The fully qualified class name of the factory', false, ArrayFormFactory::class);
63  $this->registerArgument('prototypeName', 'string', 'Name of the prototype to use', false, null);
64  $this->registerArgument('overrideConfiguration', 'array', 'factory specific configuration', false, []);
65  }
66 
74  public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
75  {
76  $persistenceIdentifier = $arguments['persistenceIdentifier'];
77  $factoryClass = $arguments['factoryClass'];
78  $prototypeName = $arguments['prototypeName'];
79  $overrideConfiguration = $arguments['overrideConfiguration'];
80 
81  if (!empty($persistenceIdentifier)) {
82  $formPersistenceManager = $renderingContext->getObjectManager()->get(FormPersistenceManagerInterface::class);
83  $formConfiguration = $formPersistenceManager->load($persistenceIdentifier);
85  $formConfiguration,
86  $overrideConfiguration
87  );
88  $overrideConfiguration = $formConfiguration;
89  $overrideConfiguration['persistenceIdentifier'] = $persistenceIdentifier;
90  }
91 
92  if (empty($prototypeName)) {
93  $prototypeName = isset($overrideConfiguration['prototypeName']) ? $overrideConfiguration['prototypeName'] : 'standard';
94  }
95 
96  $factory = $renderingContext->getObjectManager()->get($factoryClass);
97  $formDefinition = $factory->build($overrideConfiguration, $prototypeName);
98  $response = $renderingContext->getControllerContext()->getResponse() ?? $renderingContext->getObjectManager()->get(Response::class);
99  $form = $formDefinition->bind($renderingContext->getControllerContext()->getRequest(), $response);
100 
101  // If the controller context does not contain a response object, this viewhelper is used in a
102  // fluid template rendered by the FluidTemplateContentObject. Handle the StopActionException
103  // as there is no extbase dispatcher involved that catches that. */
104  if ($renderingContext->getControllerContext()->getResponse() === null) {
105  try {
106  return $form->render();
107  } catch (\TYPO3\CMS\Extbase\Mvc\Exception\StopActionException $exception) {
108  return $response->shutdown();
109  }
110  }
111 
112  return $form->render();
113  }
114 }
static renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)