‪TYPO3CMS  9.5
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 
26 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
27 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
28 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
29 
45 class ‪RenderViewHelper extends AbstractViewHelper
46 {
47  use CompileWithRenderStatic;
48 
52  protected ‪$escapeOutput = false;
53 
59  public function ‪initializeArguments()
60  {
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 
73  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
74  {
75  $persistenceIdentifier = $arguments['persistenceIdentifier'];
76  $factoryClass = $arguments['factoryClass'];
77  $prototypeName = $arguments['prototypeName'];
78  $overrideConfiguration = $arguments['overrideConfiguration'];
79 
80  $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
81  if (!empty($persistenceIdentifier)) {
82  $formPersistenceManager = $objectManager->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 = $overrideConfiguration['prototypeName'] ?? 'standard';
94  }
95 
96  $factory = $objectManager->get($factoryClass);
97  $formDefinition = $factory->build($overrideConfiguration, $prototypeName);
98  $response = $renderingContext->getControllerContext()->getResponse() ?? $objectManager->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 }
‪TYPO3\CMS\Form\Domain\Factory\ArrayFormFactory
Definition: ArrayFormFactory.php:36
‪TYPO3\CMS\Form\ViewHelpers\RenderViewHelper\$escapeOutput
‪bool $escapeOutput
Definition: RenderViewHelper.php:50
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3
‪TYPO3\CMS\Core\Utility\ArrayUtility\mergeRecursiveWithOverrule
‪static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
Definition: ArrayUtility.php:614
‪TYPO3\CMS\Extbase\Mvc\Web\Response
Definition: Response.php:25
‪TYPO3\CMS\Form\ViewHelpers\RenderViewHelper
Definition: RenderViewHelper.php:46
‪TYPO3\CMS\Form\ViewHelpers\RenderViewHelper\initializeArguments
‪initializeArguments()
Definition: RenderViewHelper.php:57
‪TYPO3\CMS\Form\ViewHelpers
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:23
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManagerInterface
Definition: FormPersistenceManagerInterface.php:28
‪TYPO3\CMS\Form\ViewHelpers\RenderViewHelper\renderStatic
‪static string renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: RenderViewHelper.php:71
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:25