[TASK] Migrate EXT:form slots to PSR-14 listeners 64/62364/3
authorBenni Mack <benni@typo3.org>
Thu, 21 Nov 2019 21:51:25 +0000 (22:51 +0100)
committerRalf Zimmermann <ralf.zimmermann@tritum.de>
Fri, 22 Nov 2019 10:42:21 +0000 (11:42 +0100)
EXT:form consumes migrated Signals in FAL, which
should be migrated in order to avoid deprecations.

All FAL logic and persistence functionality
continues to work as is.

Resolves: #89734
Releases: master
Change-Id: Ife4785ba73159bf49b7ed76a6705ce5bb2361fac
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/62364
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Daniel Goerz <daniel.goerz@posteo.de>
Tested-by: Ralf Zimmermann <ralf.zimmermann@tritum.de>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Ralf Zimmermann <ralf.zimmermann@tritum.de>
typo3/sysext/form/Classes/Slot/FilePersistenceSlot.php
typo3/sysext/form/Configuration/Services.yaml
typo3/sysext/form/ext_localconf.php

index 7b87eb1..e072f63 100644 (file)
@@ -15,7 +15,12 @@ namespace TYPO3\CMS\Form\Slot;
  * The TYPO3 project - inspiring people to share!
  */
 
-use TYPO3\CMS\Core\Resource\FileInterface;
+use TYPO3\CMS\Core\Resource\Event\BeforeFileAddedEvent;
+use TYPO3\CMS\Core\Resource\Event\BeforeFileContentsSetEvent;
+use TYPO3\CMS\Core\Resource\Event\BeforeFileCreatedEvent;
+use TYPO3\CMS\Core\Resource\Event\BeforeFileMovedEvent;
+use TYPO3\CMS\Core\Resource\Event\BeforeFileRenamedEvent;
+use TYPO3\CMS\Core\Resource\Event\BeforeFileReplacedEvent;
 use TYPO3\CMS\Core\Resource\FolderInterface;
 use TYPO3\CMS\Core\SingletonInterface;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
@@ -23,9 +28,11 @@ use TYPO3\CMS\Core\Utility\StringUtility;
 use TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManager;
 
 /**
- * @internal
+ * A PSR-14 event listener for various FAL related functionality.
+ *
+ * @internal will be renamed at some point.
  */
-class FilePersistenceSlot implements SingletonInterface
+final class FilePersistenceSlot implements SingletonInterface
 {
     const COMMAND_FILE_ADD = 'fileAdd';
     const COMMAND_FILE_CREATE = 'fileCreate';
@@ -106,15 +113,11 @@ class FilePersistenceSlot implements SingletonInterface
         return true;
     }
 
-    /**
-     * @param string $fileName
-     * @param FolderInterface $targetFolder
-     */
-    public function onPreFileCreate(string $fileName, FolderInterface $targetFolder): void
+    public function onPreFileCreate(BeforeFileCreatedEvent $event): void
     {
         $combinedFileIdentifier = $this->buildCombinedIdentifier(
-            $targetFolder,
-            $fileName
+            $event->getFolder(),
+            $event->getFileName()
         );
 
         $this->assertFileName(
@@ -123,19 +126,11 @@ class FilePersistenceSlot implements SingletonInterface
         );
     }
 
-    /**
-     * @param string $targetFileName
-     * @param FolderInterface $targetFolder
-     * @param string $sourceFilePath
-     */
-    public function onPreFileAdd(
-        string $targetFileName,
-        FolderInterface $targetFolder,
-        string $sourceFilePath
-    ): void {
+    public function onPreFileAdd(BeforeFileAddedEvent $event): void
+    {
         $combinedFileIdentifier = $this->buildCombinedIdentifier(
-            $targetFolder,
-            $targetFileName
+            $event->getTargetFolder(),
+            $event->getFileName()
         );
         // while assertFileName below also checks if it's a form definition
         // we want an early return here to get rid of the file_get_contents
@@ -146,19 +141,15 @@ class FilePersistenceSlot implements SingletonInterface
         $this->assertFileName(
             self::COMMAND_FILE_ADD,
             $combinedFileIdentifier,
-            file_get_contents($sourceFilePath)
+            file_get_contents($event->getSourceFilePath())
         );
     }
 
-    /**
-     * @param FileInterface $file
-     * @param string $targetFileName
-     */
-    public function onPreFileRename(FileInterface $file, string $targetFileName): void
+    public function onPreFileRename(BeforeFileRenamedEvent $event): void
     {
         $combinedFileIdentifier = $this->buildCombinedIdentifier(
-            $file->getParentFolder(),
-            $targetFileName
+            $event->getFile()->getParentFolder(),
+            $event->getTargetFileName()
         );
 
         $this->assertFileName(
@@ -167,15 +158,11 @@ class FilePersistenceSlot implements SingletonInterface
         );
     }
 
-    /**
-     * @param FileInterface $file
-     * @param string $localFilePath
-     */
-    public function onPreFileReplace(FileInterface $file, string $localFilePath): void
+    public function onPreFileReplace(BeforeFileReplacedEvent $event): void
     {
         $combinedFileIdentifier = $this->buildCombinedIdentifier(
-            $file->getParentFolder(),
-            $file->getName()
+            $event->getFile()->getParentFolder(),
+            $event->getFile()->getName()
         );
 
         $this->assertFileName(
@@ -184,26 +171,21 @@ class FilePersistenceSlot implements SingletonInterface
         );
     }
 
-    /**
-     * @param FileInterface $file
-     * @param FolderInterface $targetFolder
-     * @param string $targetFileName
-     */
-    public function onPreFileMove(FileInterface $file, FolderInterface $targetFolder, string $targetFileName): void
+    public function onPreFileMove(BeforeFileMovedEvent $event): void
     {
         // Skip check, in case file extension would not change during this
         // command. In case e.g. "file.txt" shall be renamed to "file.form.yaml"
         // the invocation still has to be granted.
         // Any file moved to a recycle folder is accepted as well.
-        if ($this->isFormDefinition($file->getIdentifier())
-            && $this->isFormDefinition($targetFileName)
-            || $this->isRecycleFolder($targetFolder)) {
+        if ($this->isFormDefinition($event->getFile()->getIdentifier())
+            && $this->isFormDefinition($event->getTargetFileName())
+            || $this->isRecycleFolder($event->getFolder())) {
             return;
         }
 
         $combinedFileIdentifier = $this->buildCombinedIdentifier(
-            $targetFolder,
-            $targetFileName
+            $event->getFolder(),
+            $event->getTargetFileName()
         );
 
         $this->assertFileName(
@@ -212,21 +194,17 @@ class FilePersistenceSlot implements SingletonInterface
         );
     }
 
-    /**
-     * @param FileInterface $file
-     * @param mixed $content
-     */
-    public function onPreFileSetContents(FileInterface $file, $content = null): void
+    public function onPreFileSetContents(BeforeFileContentsSetEvent $event): void
     {
         $combinedFileIdentifier = $this->buildCombinedIdentifier(
-            $file->getParentFolder(),
-            $file->getName()
+            $event->getFile()->getParentFolder(),
+            $event->getFile()->getName()
         );
 
         $this->assertFileName(
             self::COMMAND_FILE_SET_CONTENTS,
             $combinedFileIdentifier,
-            $content
+            $event->getContent()
         );
     }
 
index 73e18e6..ad50bbf 100644 (file)
@@ -7,3 +7,30 @@ services:
   TYPO3\CMS\Form\:
     resource: '../Classes/*'
     exclude: '../Classes/{Domain/Model}'
+
+  TYPO3\CMS\Form\Slot\FilePersistenceSlot:
+    tags:
+      - name: event.listener
+        identifier: 'form-framework/creation'
+        method: 'onPreFileCreate'
+        event: TYPO3\CMS\Core\Resource\Event\BeforeFileCreatedEvent
+      - name: event.listener
+        identifier: 'form-framework/add'
+        method: 'onPreFileAdd'
+        event: TYPO3\CMS\Core\Resource\Event\BeforeFileAddedEvent
+      - name: event.listener
+        identifier: 'form-framework/rename'
+        method: 'onPreFileRename'
+        event: TYPO3\CMS\Core\Resource\Event\BeforeFileRenamedEvent
+      - name: event.listener
+        identifier: 'form-framework/replace'
+        method: 'onPreFileReplace'
+        event: TYPO3\CMS\Core\Resource\Event\BeforeFileReplacedEvent
+      - name: event.listener
+        identifier: 'form-framework/move'
+        method: 'onPreFileMove'
+        event: TYPO3\CMS\Core\Resource\Event\BeforeFileMovedEvent
+      - name: event.listener
+        identifier: 'form-framework/update-content'
+        method: 'onPreFileSetContents'
+        event: TYPO3\CMS\Core\Resource\Event\BeforeFileContentsSetEvent
index 448fb64..84d813a 100644 (file)
@@ -88,45 +88,4 @@ call_user_func(function () {
         [\TYPO3\CMS\Form\Controller\FormFrontendController::class => 'perform'],
         \TYPO3\CMS\Extbase\Utility\ExtensionUtility::PLUGIN_TYPE_CONTENT_ELEMENT
     );
-
-    // Register slots for file handling
-    $signalSlotDispatcher = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
-        \TYPO3\CMS\Extbase\SignalSlot\Dispatcher::class
-    );
-    $signalSlotDispatcher->connect(
-        \TYPO3\CMS\Core\Resource\ResourceStorage::class,
-        \TYPO3\CMS\Core\Resource\ResourceStorageInterface::SIGNAL_PreFileCreate,
-        \TYPO3\CMS\Form\Slot\FilePersistenceSlot::class,
-        'onPreFileCreate'
-    );
-    $signalSlotDispatcher->connect(
-        \TYPO3\CMS\Core\Resource\ResourceStorage::class,
-        \TYPO3\CMS\Core\Resource\ResourceStorageInterface::SIGNAL_PreFileAdd,
-        \TYPO3\CMS\Form\Slot\FilePersistenceSlot::class,
-        'onPreFileAdd'
-    );
-    $signalSlotDispatcher->connect(
-        \TYPO3\CMS\Core\Resource\ResourceStorage::class,
-        \TYPO3\CMS\Core\Resource\ResourceStorageInterface::SIGNAL_PreFileRename,
-        \TYPO3\CMS\Form\Slot\FilePersistenceSlot::class,
-        'onPreFileRename'
-    );
-    $signalSlotDispatcher->connect(
-        \TYPO3\CMS\Core\Resource\ResourceStorage::class,
-        \TYPO3\CMS\Core\Resource\ResourceStorageInterface::SIGNAL_PreFileReplace,
-        \TYPO3\CMS\Form\Slot\FilePersistenceSlot::class,
-        'onPreFileReplace'
-    );
-    $signalSlotDispatcher->connect(
-        \TYPO3\CMS\Core\Resource\ResourceStorage::class,
-        \TYPO3\CMS\Core\Resource\ResourceStorageInterface::SIGNAL_PreFileMove,
-        \TYPO3\CMS\Form\Slot\FilePersistenceSlot::class,
-        'onPreFileMove'
-    );
-    $signalSlotDispatcher->connect(
-        \TYPO3\CMS\Core\Resource\ResourceStorage::class,
-        \TYPO3\CMS\Core\Resource\ResourceStorageInterface::SIGNAL_PreFileSetContents,
-        \TYPO3\CMS\Form\Slot\FilePersistenceSlot::class,
-        'onPreFileSetContents'
-    );
 });