‪TYPO3CMS  11.5
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  if (!empty($persistenceIdentifier)) {
86  $formPersistenceManager = GeneralUtility::makeInstance(FormPersistenceManagerInterface::class);
87  $formConfiguration = $formPersistenceManager->load($persistenceIdentifier);
89  $formConfiguration,
90  $overrideConfiguration
91  );
92  $overrideConfiguration = $formConfiguration;
93  $overrideConfiguration['persistenceIdentifier'] = $persistenceIdentifier;
94  }
95 
96  if (empty($prototypeName)) {
97  $prototypeName = $overrideConfiguration['prototypeName'] ?? 'standard';
98  }
99 
100  // Even though getContainer() is internal, we can't get container injected here due to static scope
101  $container = GeneralUtility::getContainer();
102  if ($container->has($factoryClass)) {
104  $factory = $container->get($factoryClass);
105  } else {
106  // @deprecated since TYPO3 v11, will be removed in TYPO3 v12.0
108  $factory = GeneralUtility::makeInstance(ObjectManager::class)->get($factoryClass);
109  }
110 
111  $formDefinition = $factory->build($overrideConfiguration, $prototypeName);
112  $form = $formDefinition->bind($renderingContext->getRequest());
113 
114  // If the controller context does not contain a response object, this viewhelper is used in a
115  // fluid template rendered by the FluidTemplateContentObject. Handle the StopActionException
116  // as there is no extbase dispatcher involved that catches that. */
117  try {
118  return $form->render();
119  } catch (‪StopActionException $exception) {
120  // @deprecated since v11, will be removed in v12: StopActionException is deprecated, drop this catch block.
121  // RedirectFinisher for throws a PropagateResponseException instead which bubbles up into Middleware.
122  trigger_error(
123  'Throwing StopActionException is deprecated. If really needed, throw a (internal) PropagateResponseException'
124  . ' instead, for now. Note this is subject to change.',
125  E_USER_DEPRECATED
126  );
127  return $exception->‪getResponse()->getBody()->getContents();
128  }
129  }
130 }
‪TYPO3\CMS\Form\Domain\Factory\ArrayFormFactory
Definition: ArrayFormFactory.php:39
‪TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
Definition: StopActionException.php:37
‪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\Form\ViewHelpers\RenderViewHelper
Definition: RenderViewHelper.php:51
‪TYPO3\CMS\Form\Domain\Factory\FormFactoryInterface
Definition: FormFactoryInterface.php:37
‪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:50
‪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:31
‪TYPO3\CMS\Extbase\Mvc\Exception\StopActionException\getResponse
‪getResponse()
Definition: StopActionException.php:51