[TASK] Resolve cross dep between EXT:backend and EXT:feedit 11/52011/4
authorClaus Due <claus@namelesscoder.net>
Sun, 12 Mar 2017 13:26:22 +0000 (14:26 +0100)
committerGeorg Ringer <georg.ringer@gmail.com>
Thu, 16 Mar 2017 05:03:38 +0000 (06:03 +0100)
This patch moves frontend-editing intialisation from the
EditDocumentController (EXT:backend) to a signal listener
in EXT:feedit. Step towards extracting EXT:feedit to TER.

Change-Id: I09a7e5a2205e7020e7145023d7d63c61d9be508c
Resolves: #80244
Releases: master
Reviewed-on: https://review.typo3.org/52011
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
typo3/sysext/backend/Classes/Controller/EditDocumentController.php
typo3/sysext/feedit/Classes/FrontendEditAssetLoader.php [new file with mode: 0644]
typo3/sysext/feedit/ext_localconf.php

index 452cda5..60de056 100644 (file)
@@ -748,28 +748,6 @@ class EditDocumentController extends AbstractModule
         );
         $t3Configuration = [];
 
-        if (ExtensionManagementUtility::isLoaded('feedit') && (int)GeneralUtility::_GP('feEdit') === 1) {
-            // We have to load some locallang strings and push them into TYPO3.LLL if this request was
-            // triggered by feedit. Originally, this object is fed by BackendController which is not
-            // called here. This block of code is intended to be removed at a later point again.
-            $lang = $this->getLanguageService();
-            $coreLabels = [
-                'csh_tooltip_loading' => $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:csh_tooltip_loading')
-            ];
-            $generatedLabels = [];
-            $generatedLabels['core'] = $coreLabels;
-            $code = 'TYPO3.LLL = ' . json_encode($generatedLabels) . ';';
-            $filePath = 'typo3temp/assets/js/backend-' . sha1($code) . '.js';
-            if (!file_exists(PATH_site . $filePath)) {
-                // writeFileToTypo3tempDir() returns NULL on success (please double-read!)
-                $error = GeneralUtility::writeFileToTypo3tempDir(PATH_site . $filePath, $code);
-                if ($error !== null) {
-                    throw new \RuntimeException('Locallang JS file could not be written to ' . $filePath . '. Reason: ' . $error, 1446118286);
-                }
-            }
-            $pageRenderer->addJsFile('../' . $filePath);
-        }
-
         $javascript = '
                        TYPO3.configuration = ' . json_encode($t3Configuration) . ';
                        // Object: TS:
diff --git a/typo3/sysext/feedit/Classes/FrontendEditAssetLoader.php b/typo3/sysext/feedit/Classes/FrontendEditAssetLoader.php
new file mode 100644 (file)
index 0000000..1d4a889
--- /dev/null
@@ -0,0 +1,65 @@
+<?php
+namespace TYPO3\CMS\Feedit;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use TYPO3\CMS\Backend\Controller\EditDocumentController;
+use TYPO3\CMS\Core\Page\PageRenderer;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
+/**
+ * Class FrontendEditAssetLoader
+ */
+class FrontendEditAssetLoader
+{
+    /**
+     * @param EditDocumentController $controller
+     * @return void
+     */
+    public function attachAssets(EditDocumentController $controller)
+    {
+        if ((int)GeneralUtility::_GP('feEdit') === 1) {
+            $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
+            // We have to load some locallang strings and push them into TYPO3.LLL if this request was
+            // triggered by feedit. Originally, this object is fed by BackendController which is not
+            // called here. This block of code is intended to be removed at a later point again.
+            $lang = $this->getLanguageService();
+            $coreLabels = [
+                'csh_tooltip_loading' => $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:csh_tooltip_loading')
+            ];
+            $generatedLabels = [];
+            $generatedLabels['core'] = $coreLabels;
+            $code = 'TYPO3.LLL = ' . json_encode($generatedLabels) . ';';
+            $filePath = 'typo3temp/assets/js/backend-' . sha1($code) . '.js';
+            if (!file_exists(PATH_site . $filePath)) {
+                // writeFileToTypo3tempDir() returns NULL on success (please double-read!)
+                $error = GeneralUtility::writeFileToTypo3tempDir(PATH_site . $filePath, $code);
+                if ($error !== null) {
+                    throw new \RuntimeException('Locallang JS file could not be written to ' . $filePath . '. Reason: ' . $error, 1446118286);
+                }
+            }
+            $pageRenderer->addJsFile('../' . $filePath);
+        }
+    }
+
+    /**
+     * Returns LanguageService
+     *
+     * @return \TYPO3\CMS\Lang\LanguageService
+     */
+    protected function getLanguageService()
+    {
+        return $GLOBALS['LANG'];
+    }
+}
index 943ffcd..b356fa8 100644 (file)
@@ -3,3 +3,12 @@ defined('TYPO3_MODE') or die();
 
 // Register the edit panel view.
 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/classes/class.frontendedit.php']['edit'] = \TYPO3\CMS\Feedit\FrontendEditPanel::class;
+
+if (TYPO3_MODE === 'FE') {
+    \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher::class)->connect(
+        \TYPO3\CMS\Backend\Controller\EditDocumentController::class,
+        'initAfter',
+        \TYPO3\CMS\Feedit\FrontendEditAssetLoader::class,
+        'attachAssets'
+    );
+}