Skip to content

Commit

Permalink
[BUGFIX] Do not hide ContentObjectRenderer on form rendering
Browse files Browse the repository at this point in the history
With #93887 (respectively #92406), a more convenient rendering
mechanism for forms was introduced. A new FormRequestHandler
centralized all the logic from the <formvh:render> view helper
to allow smoother form handling. However, the new implementation
used to hide the current ContentObjectRenderer implementation
and instead always fetched a new instance with
GeneralUtility::makeInstance().

This no longer allows to determine the current content object
rendering context from e.g. form finishers. Since the current
implementation can be retrieved by the ConfigurationManager,
it is now used in the <formvh:render> view helper, falling
back to a new ContentObjectRenderer instance in case the
ConfigurationManager does not actually provide an instance
of ContentObjectRenderer.

Resolves: #97977
Related: #93887
Related: #92406
Releases: main, 11.5
Change-Id: Iabf4e93e6aff8da742321958730521ef1696f130
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/75247
Tested-by: core-ci <typo3@b13.com>
Tested-by: waldhacker <hello@waldhacker.dev>
Tested-by: theline <typo3@root-access.de>
Tested-by: Oliver Hader <oliver.hader@typo3.org>
Reviewed-by: waldhacker <hello@waldhacker.dev>
Reviewed-by: theline <typo3@root-access.de>
Reviewed-by: Oliver Hader <oliver.hader@typo3.org>
  • Loading branch information
eliashaeussler authored and ohader committed Aug 15, 2022
1 parent 0303a9c commit d3d8bc0
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion typo3/sysext/form/Classes/ViewHelpers/RenderViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
namespace TYPO3\CMS\Form\ViewHelpers;

use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Extbase\Mvc\Request;
use TYPO3\CMS\Form\Core\FormRequestHandler;
use TYPO3\CMS\Form\Domain\Factory\ArrayFormFactory;
Expand Down Expand Up @@ -64,7 +65,9 @@ public static function renderStatic(array $arguments, \Closure $renderChildrenCl
{
$request = $renderingContext->getRequest();
$extensionName = $request instanceof Request ? $request->getControllerExtensionName() : 'Form';
return GeneralUtility::makeInstance(ContentObjectRenderer::class)->cObjGetSingle('USER', [
$contentObjectRenderer = self::getContentObjectRenderer();

return $contentObjectRenderer->cObjGetSingle('USER', [
'userFunc' => FormRequestHandler::class . '->process',
'persistenceIdentifier' => $arguments['persistenceIdentifier'],
'factoryClass' => $arguments['factoryClass'],
Expand All @@ -74,4 +77,16 @@ public static function renderStatic(array $arguments, \Closure $renderChildrenCl
'pluginName' => $request->getPluginName(),
]);
}

private static function getContentObjectRenderer(): ContentObjectRenderer
{
$configurationManager = GeneralUtility::makeInstance(ConfigurationManagerInterface::class);
$contentObjectRenderer = $configurationManager->getContentObject();

if ($contentObjectRenderer === null) {
$contentObjectRenderer = GeneralUtility::makeInstance(ContentObjectRenderer::class);
}

return $contentObjectRenderer;
}
}

0 comments on commit d3d8bc0

Please sign in to comment.