[TASK] Migrate FileMetadataOverlayAspect to PSR-14 listener 88/62388/3
authorBenni Mack <benni@typo3.org>
Fri, 22 Nov 2019 17:58:06 +0000 (18:58 +0100)
committerSusanne Moog <look@susi.dev>
Mon, 25 Nov 2019 08:51:39 +0000 (09:51 +0100)
The existing slot in EXT:frontend for overlaying sys-file-metadata
is migrated to a PSR-14 event listener.

Although this is not a new feature, this is a perfect example of
a migration from SignalSlot to PSR-14 event listener.

Resolves: #89748
Releases: master
Change-Id: I98fb14b0b9c56ea9d8938e29be88ddcf8dd43eb5
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/62388
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Daniel Gorges <daniel.gorges@b13.com>
Reviewed-by: Susanne Moog <look@susi.dev>
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Daniel Gorges <daniel.gorges@b13.com>
Tested-by: Susanne Moog <look@susi.dev>
typo3/sysext/frontend/Classes/Aspect/FileMetadataOverlayAspect.php
typo3/sysext/frontend/Configuration/Services.yaml
typo3/sysext/frontend/ext_localconf.php

index 9046673..5a44425 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+declare(strict_types = 1);
 namespace TYPO3\CMS\Frontend\Aspect;
 
 /*
@@ -15,42 +16,39 @@ namespace TYPO3\CMS\Frontend\Aspect;
  */
 
 use TYPO3\CMS\Core\Domain\Repository\PageRepository;
+use TYPO3\CMS\Core\Resource\Event\EnrichFileMetaDataEvent;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
- * Class FileMetadataTranslationAspect
+ * This class deals with metadata translation as a event listener which reacts on an event MetadataRepository.
  *
- * We do not have AOP in TYPO3 for now, thus the aspect which
- * deals with metadata translation is a slot which reacts on a signal
- * in the Index\MetadataRepository.
- *
- * The aspect injects user permissions and mount points into the storage
+ * The listener injects user permissions and mount points into the storage
  * based on user or group configuration.
  *
- * @internal this is a concrete TYPO3 hook implementation and solely used for EXT:frontend and not part of TYPO3's Core API.
+ * @internal this is a concrete TYPO3 Event Listener and solely used for EXT:frontend and not part of TYPO3's Core API.
  */
-class FileMetadataOverlayAspect
+final class FileMetadataOverlayAspect
 {
     /**
      * Do translation and workspace overlay
-     *
-     * @param \ArrayObject $data
+     * @param EnrichFileMetaDataEvent $event
      */
-    public function languageAndWorkspaceOverlay(\ArrayObject $data)
+    public function languageAndWorkspaceOverlay(EnrichFileMetaDataEvent $event): void
     {
         // Should only be in Frontend, but not in eID context
         if (!(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_FE) || isset($_REQUEST['eID'])) {
             return;
         }
-        $overlaidMetaData = $data->getArrayCopy();
+        $overlaidMetaData = $event->getRecord();
         $pageRepository = GeneralUtility::makeInstance(PageRepository::class);
         $pageRepository->versionOL('sys_file_metadata', $overlaidMetaData);
-        $overlaidMetaData = $pageRepository->getLanguageOverlay(
-            'sys_file_metadata',
-            $overlaidMetaData
-        );
+        $overlaidMetaData = $pageRepository
+            ->getLanguageOverlay(
+                'sys_file_metadata',
+                $overlaidMetaData
+            );
         if ($overlaidMetaData !== null) {
-            $data->exchangeArray($overlaidMetaData);
+            $event->setRecord($overlaidMetaData);
         }
     }
 }
index 0a7c638..a949c44 100644 (file)
@@ -16,3 +16,10 @@ services:
   TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer:
     public: true
     shared: false
+
+  TYPO3\CMS\Frontend\Aspect\FileMetadataOverlayAspect:
+    tags:
+      - name: event.listener
+        identifier: 'typo3-frontend/overlay'
+        method: 'languageAndWorkspaceOverlay'
+        event: TYPO3\CMS\Core\Resource\Event\EnrichFileMetaDataEvent
index 75c3e71..c24c140 100644 (file)
@@ -1,13 +1,6 @@
 <?php
 defined('TYPO3_MODE') or die();
 
-\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher::class)->connect(
-    \TYPO3\CMS\Core\Resource\Index\MetaDataRepository::class,
-    'recordPostRetrieval',
-    \TYPO3\CMS\Frontend\Aspect\FileMetadataOverlayAspect::class,
-    'languageAndWorkspaceOverlay'
-);
-
 // Register all available content objects
 $GLOBALS['TYPO3_CONF_VARS']['FE']['ContentObjects'] = array_merge($GLOBALS['TYPO3_CONF_VARS']['FE']['ContentObjects'], [
     'TEXT'             => \TYPO3\CMS\Frontend\ContentObject\TextContentObject::class,