From 846abdca3459b76e961620a8315162f46efe1a2f Mon Sep 17 00:00:00 2001
From: Oliver Hader <oliver@typo3.org>
Date: Mon, 23 Aug 2021 21:29:22 +0200
Subject: [PATCH] [TASK] Simplify stylesheet and script assignments in ext:form

Avoids round trip through Fluid template, but instead assigns
stylesheets and inline scripts directly via `PageRenderer`.

Resolves: #94969
Releases: master
Change-Id: Ic16c853fc8fcb26204c91b6347616513787fcd78
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/70731
Tested-by: core-ci <typo3@b13.com>
Tested-by: Benni Mack <benni@typo3.org>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
---
 .../Classes/Controller/FormEditorController.php   | 15 +++++++++------
 .../Private/Backend/Layouts/FormEditor.html       |  1 -
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/typo3/sysext/form/Classes/Controller/FormEditorController.php b/typo3/sysext/form/Classes/Controller/FormEditorController.php
index 115cf6039619..7071fdf69963 100644
--- a/typo3/sysext/form/Classes/Controller/FormEditorController.php
+++ b/typo3/sysext/form/Classes/Controller/FormEditorController.php
@@ -120,12 +120,9 @@ class FormEditorController extends AbstractBackendController
             'maximumUndoSteps' => $this->prototypeConfiguration['formEditor']['maximumUndoSteps'],
         ];
 
-        $this->view->assign('stylesheets', $this->resolveResourcePaths($this->prototypeConfiguration['formEditor']['stylesheets']));
         $this->view->assign('formEditorTemplates', $this->renderFormEditorTemplates($formEditorDefinitions));
         $this->view->assign('dynamicRequireJsModules', $this->prototypeConfiguration['formEditor']['dynamicRequireJsModules']);
 
-        $this->getPageRenderer()->addInlineLanguageLabelFile('EXT:form/Resources/Private/Language/locallang_formEditor_failSafeErrorHandling_javascript.xlf');
-
         $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
         $addInlineSettings = [
             'FormEditor' => [
@@ -143,8 +140,6 @@ class FormEditorController extends AbstractBackendController
             $formDefinition['label']
         );
 
-        $this->view->assign('addInlineSettings', $addInlineSettings);
-
         $formEditorAppInitialData = json_encode($formEditorAppInitialData);
         if ($formEditorAppInitialData === false) {
             throw new Exception('The form editor app data could not be encoded', 1628677079);
@@ -158,7 +153,15 @@ class FormEditorController extends AbstractBackendController
                 viewModel
             ).run();
         });';
-        $this->getPageRenderer()->addJsInlineCode('formEditorIndex', $script);
+
+        $pageRenderer = $this->getPageRenderer();
+        $pageRenderer->addJsInlineCode('formEditorIndex', $script);
+        $pageRenderer->addInlineSettingArray(null, $addInlineSettings);
+        $pageRenderer->addInlineLanguageLabelFile('EXT:form/Resources/Private/Language/locallang_formEditor_failSafeErrorHandling_javascript.xlf');
+        $stylesheets = $this->resolveResourcePaths($this->prototypeConfiguration['formEditor']['stylesheets']);
+        foreach ($stylesheets as $stylesheet) {
+            $pageRenderer->addCssFile($stylesheet);
+        }
 
         return $this->htmlResponse();
     }
diff --git a/typo3/sysext/form/Resources/Private/Backend/Layouts/FormEditor.html b/typo3/sysext/form/Resources/Private/Backend/Layouts/FormEditor.html
index 23d1b7a6b4d5..801803054b0d 100644
--- a/typo3/sysext/form/Resources/Private/Backend/Layouts/FormEditor.html
+++ b/typo3/sysext/form/Resources/Private/Backend/Layouts/FormEditor.html
@@ -1,5 +1,4 @@
 <html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" xmlns:formvh="http://typo3.org/ns/TYPO3/CMS/Form/ViewHelpers" data-namespace-typo3-fluid="true">
-<f:be.pageRenderer includeCssFiles="{stylesheets}" addInlineSettings="{addInlineSettings}" includeJsFiles="{0: 'EXT:backend/Resources/Public/JavaScript/jsfunc.tbe_editor.js'}" />
 <div data-identifier="moduleLoadingIndicator" class="form-editor-loading-spinner">
     <core:icon identifier="spinner-circle-dark" size="default" />
     <div class="form-editor-loading-spinner-label"><f:translate key="LLL:EXT:form/Resources/Private/Language/Database.xlf:formEditor.loading" /></div>
-- 
GitLab