‪TYPO3CMS  ‪main
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 final class ‪RenderViewHelper extends AbstractViewHelper
51 {
52  use CompileWithRenderStatic;
53 
57  protected ‪$escapeOutput = false;
58 
59  public function ‪initializeArguments(): void
60  {
61  $this->registerArgument('persistenceIdentifier', 'string', 'The persistence identifier for the form.', false);
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);
64  $this->registerArgument('overrideConfiguration', 'array', 'factory specific configuration', false, []);
65  }
66 
67  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): ?string
68  {
69  $persistenceIdentifier = $arguments['persistenceIdentifier'];
70  $factoryClass = $arguments['factoryClass'];
71  $prototypeName = $arguments['prototypeName'];
72  $overrideConfiguration = $arguments['overrideConfiguration'];
73 
74  if (!empty($persistenceIdentifier)) {
75  $formPersistenceManager = GeneralUtility::makeInstance(FormPersistenceManagerInterface::class);
76  $formConfiguration = $formPersistenceManager->load($persistenceIdentifier);
77  ArrayUtility::mergeRecursiveWithOverrule(
78  $formConfiguration,
79  $overrideConfiguration
80  );
81  $overrideConfiguration = $formConfiguration;
82  $overrideConfiguration['persistenceIdentifier'] = $persistenceIdentifier;
83  }
84 
85  if (empty($prototypeName)) {
86  $prototypeName = $overrideConfiguration['prototypeName'] ?? 'standard';
87  }
88 
89  // Even though getContainer() is internal, we can't get container injected here due to static scope
91  $factory = GeneralUtility::getContainer()->get($factoryClass);
92 
93  $formDefinition = $factory->build($overrideConfiguration, $prototypeName);
96  $request = $renderingContext->getRequest();
97  $form = $formDefinition->bind($request);
98 
99  return $form->render();
100  }
101 }
‪TYPO3\CMS\Form\Domain\Factory\ArrayFormFactory
Definition: ArrayFormFactory.php:39
‪TYPO3\CMS\Form\ViewHelpers\RenderViewHelper\$escapeOutput
‪bool $escapeOutput
Definition: RenderViewHelper.php:55
‪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:57
‪TYPO3\CMS\Extbase\Mvc\RequestInterface
Definition: RequestInterface.php:24
‪TYPO3\CMS\Form\ViewHelpers
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:26
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManagerInterface
Definition: FormPersistenceManagerInterface.php:32
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext
Definition: RenderingContext.php:35
‪TYPO3\CMS\Form\ViewHelpers\RenderViewHelper\renderStatic
‪static renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: RenderViewHelper.php:65