[TASK] Streamline FAL pre-emit signals for createFile and setContent 18/57418/2
authorOliver Hader <oliver@typo3.org>
Fri, 29 Jun 2018 13:02:29 +0000 (15:02 +0200)
committerFrans Saris <franssaris@gmail.com>
Sat, 30 Jun 2018 06:42:39 +0000 (08:42 +0200)
In order to streamline the FAL API the following signals have been added.
The according post-processing signals have been available already before:

+ ResourceStorageInterface::SIGNAL_PreFileCreate
+ ResourceStorageInterface::SIGNAL_PreFileSetContents

Resolves: #85434
Releases: master, 8.7
Change-Id: I41fc07afbc4e1a393c8a26fe02f431a7b62015d8
Reviewed-on: https://review.typo3.org/57418
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Frans Saris <franssaris@gmail.com>
Tested-by: Frans Saris <franssaris@gmail.com>
typo3/sysext/core/Classes/Resource/ResourceStorage.php
typo3/sysext/core/Classes/Resource/ResourceStorageInterface.php

index 3f311ca..d3e7c73 100644 (file)
@@ -1680,6 +1680,7 @@ class ResourceStorage implements ResourceStorageInterface
     {
         // Check if user is allowed to edit
         $this->assureFileWritePermissions($file);
     {
         // Check if user is allowed to edit
         $this->assureFileWritePermissions($file);
+        $this->emitPreFileSetContentsSignal($file, $contents);
         // Call driver method to update the file and update file index entry afterwards
         $result = $this->driver->setFileContents($file->getIdentifier(), $contents);
         if ($file instanceof File) {
         // Call driver method to update the file and update file index entry afterwards
         $result = $this->driver->setFileContents($file->getIdentifier(), $contents);
         if ($file instanceof File) {
@@ -1704,6 +1705,7 @@ class ResourceStorage implements ResourceStorageInterface
     public function createFile($fileName, Folder $targetFolderObject)
     {
         $this->assureFileAddPermissions($targetFolderObject, $fileName);
     public function createFile($fileName, Folder $targetFolderObject)
     {
         $this->assureFileAddPermissions($targetFolderObject, $fileName);
+        $this->emitPreFileCreateSignal($fileName, $targetFolderObject);
         $newFileIdentifier = $this->driver->createFile($fileName, $targetFolderObject->getIdentifier());
         $this->emitPostFileCreateSignal($newFileIdentifier, $targetFolderObject);
         return $this->getResourceFactoryInstance()->getFileObjectByStorageAndIdentifier($this->getUid(), $newFileIdentifier);
         $newFileIdentifier = $this->driver->createFile($fileName, $targetFolderObject->getIdentifier());
         $this->emitPostFileCreateSignal($newFileIdentifier, $targetFolderObject);
         return $this->getResourceFactoryInstance()->getFileObjectByStorageAndIdentifier($this->getUid(), $newFileIdentifier);
@@ -2566,6 +2568,17 @@ class ResourceStorage implements ResourceStorageInterface
     }
 
     /**
     }
 
     /**
+     * Emits the file pre-create signal
+     *
+     * @param string $fileName
+     * @param Folder $targetFolder
+     */
+    protected function emitPreFileCreateSignal(string $fileName, Folder $targetFolder)
+    {
+        $this->getSignalSlotDispatcher()->dispatch(self::class, self::SIGNAL_PreFileCreate, [$fileName, $targetFolder]);
+    }
+
+    /**
      * Emits the file post-create signal
      *
      * @param string $newFileIdentifier
      * Emits the file post-create signal
      *
      * @param string $newFileIdentifier
@@ -2597,6 +2610,17 @@ class ResourceStorage implements ResourceStorageInterface
     }
 
     /**
     }
 
     /**
+     * Emits the file pre-set-contents signal
+     *
+     * @param FileInterface $file
+     * @param mixed $content
+     */
+    protected function emitPreFileSetContentsSignal(FileInterface $file, $content)
+    {
+        $this->getSignalSlotDispatcher()->dispatch(self::class, self::SIGNAL_PreFileSetContents, [$file, $content]);
+    }
+
+    /**
      * Emits the file post-set-contents signal
      *
      * @param FileInterface $file
      * Emits the file post-set-contents signal
      *
      * @param FileInterface $file
index 83b6071..1ee4c98 100644 (file)
@@ -22,6 +22,7 @@ interface ResourceStorageInterface
     const SIGNAL_SanitizeFileName = 'sanitizeFileName';
     const SIGNAL_PreFileAdd = 'preFileAdd';
     const SIGNAL_PostFileAdd = 'postFileAdd';
     const SIGNAL_SanitizeFileName = 'sanitizeFileName';
     const SIGNAL_PreFileAdd = 'preFileAdd';
     const SIGNAL_PostFileAdd = 'postFileAdd';
+    const SIGNAL_PreFileCreate = 'preFileCreate';
     const SIGNAL_PostFileCreate = 'postFileCreate';
     const SIGNAL_PreFileCopy = 'preFileCopy';
     const SIGNAL_PostFileCopy = 'postFileCopy';
     const SIGNAL_PostFileCreate = 'postFileCreate';
     const SIGNAL_PreFileCopy = 'preFileCopy';
     const SIGNAL_PostFileCopy = 'postFileCopy';
@@ -33,6 +34,7 @@ interface ResourceStorageInterface
     const SIGNAL_PostFileRename = 'postFileRename';
     const SIGNAL_PreFileReplace = 'preFileReplace';
     const SIGNAL_PostFileReplace = 'postFileReplace';
     const SIGNAL_PostFileRename = 'postFileRename';
     const SIGNAL_PreFileReplace = 'preFileReplace';
     const SIGNAL_PostFileReplace = 'postFileReplace';
+    const SIGNAL_PreFileSetContents = 'preFileSetContents';
     const SIGNAL_PostFileSetContents = 'postFileSetContents';
     const SIGNAL_PreFolderAdd = 'preFolderAdd';
     const SIGNAL_PostFolderAdd = 'postFolderAdd';
     const SIGNAL_PostFileSetContents = 'postFileSetContents';
     const SIGNAL_PreFolderAdd = 'preFolderAdd';
     const SIGNAL_PostFolderAdd = 'postFolderAdd';