[TASK] Avoid ObjectManager->get() for ext:form FormPersistenceManagerInterface
authorChristian Kuhn <lolli@schwarzbu.ch>
Thu, 10 Jun 2021 13:28:42 +0000 (15:28 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 10 Jun 2021 14:41:39 +0000 (16:41 +0200)
Register an implementation and adapt consumers.

Resolves: #94300
Related: #90803
Releases: master
Change-Id: I43117cf3094e0784d05c97d7f28f3365d12bd1f9
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/69431
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Oliver Bartsch <bo@cedev.de>
Reviewed-by: Jochen <rothjochen@gmail.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Oliver Bartsch <bo@cedev.de>
Tested-by: Jochen <rothjochen@gmail.com>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/form/Classes/Hooks/DataStructureIdentifierHook.php
typo3/sysext/form/Classes/Hooks/FormPagePreviewRenderer.php
typo3/sysext/form/Classes/ViewHelpers/RenderViewHelper.php
typo3/sysext/form/Configuration/Services.yaml
typo3/sysext/form/Tests/Unit/Hooks/DataStructureIdentifierHookTest.php

index b201d04..51165c6 100644 (file)
@@ -23,7 +23,6 @@ use TYPO3\CMS\Core\Messaging\FlashMessage;
 use TYPO3\CMS\Core\Messaging\FlashMessageService;
 use TYPO3\CMS\Core\Utility\ArrayUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
-use TYPO3\CMS\Extbase\Object\ObjectManager;
 use TYPO3\CMS\Form\Domain\Configuration\ArrayProcessing\ArrayProcessing;
 use TYPO3\CMS\Form\Domain\Configuration\ArrayProcessing\ArrayProcessor;
 use TYPO3\CMS\Form\Domain\Configuration\ConfigurationService;
@@ -109,7 +108,7 @@ class DataStructureIdentifierHook
         if (isset($identifier['ext-form-persistenceIdentifier'])) {
             try {
                 // Add list of existing forms to drop down if we find our key in the identifier
-                $formPersistenceManager = GeneralUtility::makeInstance(ObjectManager::class)->get(FormPersistenceManagerInterface::class);
+                $formPersistenceManager = GeneralUtility::makeInstance(FormPersistenceManagerInterface::class);
                 $formIsAccessible = false;
                 foreach ($formPersistenceManager->listForms() as $form) {
                     $invalidFormDefinition = $form['invalid'] ?? false;
index ad05d8d..e396667 100644 (file)
@@ -27,7 +27,6 @@ use TYPO3\CMS\Core\Messaging\FlashMessageService;
 use TYPO3\CMS\Core\Service\FlexFormService;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\StringUtility;
-use TYPO3\CMS\Extbase\Object\ObjectManager;
 use TYPO3\CMS\Form\Mvc\Configuration\Exception\NoSuchFileException;
 use TYPO3\CMS\Form\Mvc\Configuration\Exception\ParseErrorException;
 use TYPO3\CMS\Form\Mvc\Persistence\Exception\PersistenceManagerException;
@@ -53,7 +52,7 @@ class FormPagePreviewRenderer extends StandardContentPreviewRenderer
         $persistenceIdentifier = $flexFormData['settings']['persistenceIdentifier'];
         if (!empty($persistenceIdentifier)) {
             try {
-                $formPersistenceManager = GeneralUtility::makeInstance(ObjectManager::class)->get(FormPersistenceManagerInterface::class);
+                $formPersistenceManager = GeneralUtility::makeInstance(FormPersistenceManagerInterface::class);
 
                 try {
                     if (
index 58ffbae..5e91edf 100644 (file)
@@ -83,9 +83,8 @@ class RenderViewHelper extends AbstractViewHelper
         $prototypeName = $arguments['prototypeName'];
         $overrideConfiguration = $arguments['overrideConfiguration'];
 
-        $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
         if (!empty($persistenceIdentifier)) {
-            $formPersistenceManager = $objectManager->get(FormPersistenceManagerInterface::class);
+            $formPersistenceManager = GeneralUtility::makeInstance(FormPersistenceManagerInterface::class);
             $formConfiguration = $formPersistenceManager->load($persistenceIdentifier);
             ArrayUtility::mergeRecursiveWithOverrule(
                 $formConfiguration,
@@ -99,6 +98,7 @@ class RenderViewHelper extends AbstractViewHelper
             $prototypeName = $overrideConfiguration['prototypeName'] ?? 'standard';
         }
 
+        $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
         /** @var FormFactoryInterface $factory */
         $factory = $objectManager->get($factoryClass);
         $formDefinition = $factory->build($overrideConfiguration, $prototypeName);
index f736508..fc35b0b 100644 (file)
@@ -15,6 +15,10 @@ services:
   TYPO3\CMS\Form\Mvc\Configuration\TypoScriptService:
     public: true
 
+  TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManagerInterface:
+    alias: TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManager
+    public: true
+
   TYPO3\CMS\Form\Slot\ResourcePublicationSlot:
     tags:
       - name: event.listener
index 7096fba..85f3b21 100644 (file)
@@ -21,9 +21,7 @@ use Prophecy\Argument;
 use TYPO3\CMS\Core\Cache\CacheManager;
 use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
-use TYPO3\CMS\Extbase\Object\ObjectManager;
 use TYPO3\CMS\Form\Hooks\DataStructureIdentifierHook;
-use TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManager;
 use TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManagerInterface;
 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
 
@@ -182,11 +180,8 @@ class DataStructureIdentifierHookTest extends UnitTestCase
      */
     public function parseDataStructureByIdentifierPostProcessAddsExistingFormItems(array $formDefinition, array $expectedItem): void
     {
-        $objectManagerProphecy = $this->prophesize(ObjectManager::class);
-        GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManagerProphecy->reveal());
-        $formPersistenceManagerProphecy = $this->prophesize(FormPersistenceManager::class);
-        $objectManagerProphecy->get(FormPersistenceManagerInterface::class)
-            ->willReturn($formPersistenceManagerProphecy->reveal());
+        $formPersistenceManagerProphecy = $this->prophesize(FormPersistenceManagerInterface::class);
+        GeneralUtility::addInstance(FormPersistenceManagerInterface::class, $formPersistenceManagerProphecy->reveal());
 
         $formPersistenceManagerProphecy->listForms()->shouldBeCalled()->willReturn([$formDefinition]);