[FEATURE] Add preProcessStorage signal to ResourceFactory 18/38018/8
authorFrank Nägler <typo3@naegler.net>
Sun, 22 Mar 2015 23:55:11 +0000 (00:55 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Fri, 12 Feb 2016 17:47:59 +0000 (18:47 +0100)
This patch introduces a new signal before a resource storage is initialized.
This is very useful to overwrite the storage configuration before the
storage is created.

Resolves: #72904
Releases: master
Change-Id: Iafda08938de33fd555552b70e62700823f8795b9
Reviewed-on: https://review.typo3.org/38018
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Jan Helke <typo3@helke.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Classes/Resource/ResourceFactory.php
typo3/sysext/core/Classes/Resource/ResourceFactoryInterface.php
typo3/sysext/core/Documentation/Changelog/master/Feature-72904-AddPreProcessStorageSignalToResourceFactory.rst [new file with mode: 0644]

index e08e30b..cd858ba 100644 (file)
@@ -144,6 +144,7 @@ class ResourceFactory implements ResourceFactoryInterface, \TYPO3\CMS\Core\Singl
         if (!$this->storageInstances[$uid]) {
             $storageConfiguration = null;
             $storageObject = null;
         if (!$this->storageInstances[$uid]) {
             $storageConfiguration = null;
             $storageObject = null;
+            list($_, $uid, $recordData, $fileIdentifier) = $this->emitPreProcessStorageSignal($uid, $recordData, $fileIdentifier);
             // If the built-in storage with UID=0 is requested:
             if ($uid === 0) {
                 $recordData = array(
             // If the built-in storage with UID=0 is requested:
             if ($uid === 0) {
                 $recordData = array(
@@ -181,6 +182,19 @@ class ResourceFactory implements ResourceFactoryInterface, \TYPO3\CMS\Core\Singl
     }
 
     /**
     }
 
     /**
+     * Emits a signal before a resource storage was initialized
+     *
+     * @param int $uid
+     * @param array $recordData
+     * @param string $fileIdentifier
+     * @return mixed
+     */
+    protected function emitPreProcessStorageSignal($uid, $recordData, $fileIdentifier)
+    {
+        return $this->signalSlotDispatcher->dispatch(\TYPO3\CMS\Core\Resource\ResourceFactory::class, self::SIGNAL_PreProcessStorage, array($this, $uid, $recordData, $fileIdentifier));
+    }
+
+    /**
      * Emits a signal after a resource storage was initialized
      *
      * @param ResourceStorage $storageObject
      * Emits a signal after a resource storage was initialized
      *
      * @param ResourceStorage $storageObject
index 817cc2a..b4c2c49 100644 (file)
@@ -19,5 +19,6 @@ namespace TYPO3\CMS\Core\Resource;
  */
 interface ResourceFactoryInterface
 {
  */
 interface ResourceFactoryInterface
 {
+    const SIGNAL_PreProcessStorage = 'preProcessStorage';
     const SIGNAL_PostProcessStorage = 'postProcessStorage';
 }
     const SIGNAL_PostProcessStorage = 'postProcessStorage';
 }
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-72904-AddPreProcessStorageSignalToResourceFactory.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-72904-AddPreProcessStorageSignalToResourceFactory.rst
new file mode 100644 (file)
index 0000000..c13f96e
--- /dev/null
@@ -0,0 +1,26 @@
+=================================================================
+Feature: #72904 - Add preProcessStorage signal to ResourceFactory
+=================================================================
+
+Description
+===========
+
+This patch introduces a new signal before a resource storage is initialized.
+
+Register the class which implements your logic in ``ext_localconf.php``:
+
+.. code-block:: php
+
+   $dispatcher = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher::class);
+   $dispatcher->connect(
+       \TYPO3\CMS\Core\Resource\ResourceFactory::class,
+       ResourceFactoryInterface::SIGNAL_PreProcessStorage,
+       \MY\ExtKey\Slots\ResourceFactorySlot::class,
+       'preProcessStorage'
+   );
+
+The method is called with the following arguments:
+
+* int ``$uid`` the uid of the record
+* array ``$recordData`` all record data as array
+* string ``$fileIdentifier`` the file identifier