[FEATURE] Enable frontend to show translated file metadata 66/24766/4
authorSteffen Ritter <info@rs-websystems.de>
Mon, 14 Oct 2013 21:20:02 +0000 (23:20 +0200)
committerErnesto Baschny <ernst@cron-it.de>
Tue, 15 Oct 2013 16:39:12 +0000 (18:39 +0200)
The frontend should show translated file metadata.
Since translation is not the concern of a file abstraction
layer and the FAL does not know about frontend language
settings this concern has to be decoupled.

For that purpose the MetaDataRepository has been extended
with an signal which is fired before the metadata-record
is returned. In Frontend-Context a Slot is registered
which passes that record through the according functionality
in \TYPO3\CMS\Frontend\Page\PageRepository::getRecordOverlay
so that a clean language and workspace overlay happen
according to the settings of TSFE.

Releases: 6.2
Resolves: #52818
Change-Id: I7b7791abd63d2a69480ed31861c63de1585a569c
Reviewed-on: https://review.typo3.org/24766
Reviewed-by: Frans Saris
Tested-by: Frans Saris
Reviewed-by: Fabien Udriot
Reviewed-by: Francois Suter
Tested-by: Francois Suter
Reviewed-by: Ernesto Baschny
Tested-by: Ernesto Baschny
typo3/sysext/core/Classes/Resource/Index/MetaDataRepository.php
typo3/sysext/frontend/Classes/Aspect/FileMetadataOverlayAspect.php [new file with mode: 0644]
typo3/sysext/frontend/Classes/Page/PageRepository.php
typo3/sysext/frontend/ext_localconf.php [new file with mode: 0644]

index 2197eac..e4ce8ea 100644 (file)
@@ -81,7 +81,9 @@ class MetaDataRepository implements SingletonInterface {
                        $record = $this->createMetaDataRecord($uid);
                }
 
-               return $record;
+               $passedData = new \ArrayObject($record);
+               $this->emitRecordPostRetrievalSignal($passedData);
+               return $passedData->getArrayCopy();
        }
 
        /**
@@ -132,4 +134,38 @@ class MetaDataRepository implements SingletonInterface {
                        $this->getDatabase()->exec_UPDATEquery($this->tableName, 'uid = ' . intval($row['uid']), $updateRow);
                }
        }
+
+
+       /**
+        * Get the SignalSlot dispatcher
+        *
+        * @return \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
+        */
+       protected function getSignalSlotDispatcher() {
+               return $this->getObjectManager()->get('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher');
+       }
+
+       /**
+        * Get the ObjectManager
+        *
+        * @return \TYPO3\CMS\Extbase\Object\ObjectManager
+        */
+       protected function getObjectManager() {
+               return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
+       }
+
+
+
+       /**
+        * Signal that is called after a record has been loaded from database
+        * Allows other places to do extension of metadata at runtime or
+        * for example translation and workspace overlay
+        *
+        * @param \ArrayObject $data
+        * @signal
+        */
+       protected function emitRecordPostRetrievalSignal(\ArrayObject $data) {
+               $this->getSignalSlotDispatcher()->dispatch('TYPO3\\CMS\\Core\\Resource\\Index\\MetaDataRepository', 'recordPostRetrieval', array($data));
+       }
+
 }
\ No newline at end of file
diff --git a/typo3/sysext/frontend/Classes/Aspect/FileMetadataOverlayAspect.php b/typo3/sysext/frontend/Classes/Aspect/FileMetadataOverlayAspect.php
new file mode 100644 (file)
index 0000000..ef10554
--- /dev/null
@@ -0,0 +1,65 @@
+<?php
+namespace TYPO3\CMS\Frontend\Aspect;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2013 Steffen Ritter <steffen.rittertypo3.org>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+
+/**
+ * Class FileMetadataTranslationAspect
+ *
+ * We do not have AOP in TYPO3 for now, thus the acspect 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
+ * based on user or group configuration.
+ */
+class FileMetadataOverlayAspect {
+
+       /**
+        * Do translation and workspace overlay
+        *
+        * @param \ArrayObject $data
+        * @return void
+        */
+       public function languageAndWorkspaceOverlay(\ArrayObject $data) {
+               $overlayedMetaData = $this->getTsfe()->sys_page->getRecordOverlay(
+                       'sys_file_metadata',
+                       $data->getArrayCopy(),
+                       $this->getTsfe()->sys_language_content,
+                       $this->getTsfe()->sys_language_contentOL
+               );
+               $data->exchangeArray($overlayedMetaData);
+       }
+
+       /**
+        * @return \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
+        */
+       protected function getTsfe() {
+               return $GLOBALS['TSFE'];
+       }
+}
index f095070..b828cbc 100644 (file)
@@ -357,7 +357,7 @@ class PageRepository {
                                $hookObject->getRecordOverlay_preProcess($table, $row, $sys_language_content, $OLmode, $this);
                        }
                }
-               if ($row['uid'] > 0 && $row['pid'] > 0) {
+               if ($row['uid'] > 0 && ($row['pid'] > 0 || $table == 'sys_file_metadata')) {
                        if ($GLOBALS['TCA'][$table] && $GLOBALS['TCA'][$table]['ctrl']['languageField'] && $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']) {
                                if (!$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerTable']) {
                                        // Will not be able to work with other tables (Just didn't implement it yet; Requires a scan
diff --git a/typo3/sysext/frontend/ext_localconf.php b/typo3/sysext/frontend/ext_localconf.php
new file mode 100644 (file)
index 0000000..568688d
--- /dev/null
@@ -0,0 +1,13 @@
+<?php
+if (!defined('TYPO3_MODE')) {
+       die('Access denied.');
+}
+
+if (TYPO3_MODE === 'FE') {
+       \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher')->connect(
+               'TYPO3\\CMS\\Core\\Resource\\Index\\MetaDataRepository',
+               'recordPostRetrieval',
+               'TYPO3\\CMS\\Frontend\\Aspect\\FileMetadataOverlayAspect',
+               'languageAndWorkspaceOverlay'
+       );
+}