‪TYPO3CMS  10.4
RenderViewHelper.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 
31 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
32 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
33 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
34 
50 class ‪RenderViewHelper extends AbstractViewHelper
51 {
52  use CompileWithRenderStatic;
53 
57  protected ‪$escapeOutput = false;
58 
64  public function ‪initializeArguments()
65  {
66  $this->registerArgument('persistenceIdentifier', 'string', 'The persistence identifier for the form.', false, null);
67  $this->registerArgument('factoryClass', 'string', 'The fully qualified class name of the factory', false, ArrayFormFactory::class);
68  $this->registerArgument('prototypeName', 'string', 'Name of the prototype to use', false, null);
69  $this->registerArgument('overrideConfiguration', 'array', 'factory specific configuration', false, []);
70  }
71 
78  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
79  {
80  $persistenceIdentifier = $arguments['persistenceIdentifier'];
81  $factoryClass = $arguments['factoryClass'];
82  $prototypeName = $arguments['prototypeName'];
83  $overrideConfiguration = $arguments['overrideConfiguration'];
84 
85  $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
86  if (!empty($persistenceIdentifier)) {
87  $formPersistenceManager = $objectManager->get(FormPersistenceManagerInterface::class);
88  $formConfiguration = $formPersistenceManager->load($persistenceIdentifier);
90  $formConfiguration,
91  $overrideConfiguration
92  );
93  $overrideConfiguration = $formConfiguration;
94  $overrideConfiguration['persistenceIdentifier'] = $persistenceIdentifier;
95  }
96 
97  if (empty($prototypeName)) {
98  $prototypeName = $overrideConfiguration['prototypeName'] ?? 'standard';
99  }
100 
101  $factory = $objectManager->get($factoryClass);
102  $formDefinition = $factory->build($overrideConfiguration, $prototypeName);
103  $response = $renderingContext->getControllerContext()->getResponse() ?? $objectManager->get(Response::class);
104  $form = $formDefinition->bind($renderingContext->getControllerContext()->getRequest(), $response);
105 
106  // If the controller context does not contain a response object, this viewhelper is used in a
107  // fluid template rendered by the FluidTemplateContentObject. Handle the StopActionException
108  // as there is no extbase dispatcher involved that catches that. */
109  if ($renderingContext->getControllerContext()->getResponse() === null) {
110  try {
111  return $form->render();
112  } catch (‪StopActionException $exception) {
113  return $response->shutdown();
114  }
115  }
116 
117  return $form->render();
118  }
119 }
‪TYPO3\CMS\Form\Domain\Factory\ArrayFormFactory
Definition: ArrayFormFactory.php:40
‪TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
Definition: StopActionException.php:31
‪TYPO3\CMS\Form\ViewHelpers\RenderViewHelper\$escapeOutput
‪bool $escapeOutput
Definition: RenderViewHelper.php:55
‪TYPO3\CMS\Core\Utility\ArrayUtility\mergeRecursiveWithOverrule
‪static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
Definition: ArrayUtility.php:654
‪TYPO3\CMS\Extbase\Mvc\Web\Response
Definition: Response.php:26
‪TYPO3\CMS\Form\ViewHelpers\RenderViewHelper
Definition: RenderViewHelper.php:51
‪TYPO3\CMS\Form\ViewHelpers\RenderViewHelper\initializeArguments
‪initializeArguments()
Definition: RenderViewHelper.php:62
‪TYPO3\CMS\Form\ViewHelpers
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:24
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManagerInterface
Definition: FormPersistenceManagerInterface.php:32
‪TYPO3\CMS\Form\ViewHelpers\RenderViewHelper\renderStatic
‪static string renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: RenderViewHelper.php:76
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:28