From 32062db4e5baf60fded3bfd2f69733928feb70a1 Mon Sep 17 00:00:00 2001
From: Claus Due <claus@namelesscoder.net>
Date: Sat, 28 Mar 2020 14:51:30 +0100
Subject: [PATCH] [TASK] Streamline BackendLayout API class

Followup with minor corrections for https://review.typo3.org/c/Packages/TYPO3.CMS/+/63918

* Relaxes method signature of getSelectedBackendLayout
  to restore compatibilty with third party XCLASS.
* Avoids parsing empty configuration strings (in use
  cases where configuration is passed to BackendLayout
  as array, not TS string).
* Uses DrawingConfiguration instance provided from
  BackendLayout instead of creating a new instance to
  override the one returned from BackendLayout.
* Fixes a method call with unused return value.

Releases: master
Resolves: #90839
Change-Id: If6fe1286d3ce6530de30ea4c534ac1799e63177e
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/63968
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Benni Mack <benni@typo3.org>
---
 .../backend/Classes/Controller/PageLayoutController.php   | 8 +++-----
 .../backend/Classes/View/BackendLayout/BackendLayout.php  | 2 +-
 typo3/sysext/backend/Classes/View/BackendLayoutView.php   | 6 +-----
 3 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/typo3/sysext/backend/Classes/Controller/PageLayoutController.php b/typo3/sysext/backend/Classes/Controller/PageLayoutController.php
index 75368d56c740..db66d074ea09 100644
--- a/typo3/sysext/backend/Classes/Controller/PageLayoutController.php
+++ b/typo3/sysext/backend/Classes/Controller/PageLayoutController.php
@@ -23,7 +23,6 @@ use TYPO3\CMS\Backend\Template\Components\ButtonBar;
 use TYPO3\CMS\Backend\Template\ModuleTemplate;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Backend\View\BackendLayoutView;
-use TYPO3\CMS\Backend\View\Drawing\DrawingConfiguration;
 use TYPO3\CMS\Backend\View\PageLayoutView;
 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
 use TYPO3\CMS\Core\Configuration\Features;
@@ -618,7 +617,9 @@ class PageLayoutController
         $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LayoutModule/Paste');
         $this->pageRenderer->addInlineLanguageLabelFile('EXT:backend/Resources/Private/Language/locallang_layout.xlf');
 
-        $configuration = GeneralUtility::makeInstance(DrawingConfiguration::class);
+        $backendLayout = $this->backendLayouts->getBackendLayoutForPage((int)$this->id);
+
+        $configuration = $backendLayout->getDrawingConfiguration();
         $configuration->setPageId($this->id);
         $configuration->setDefaultLanguageBinding(!empty($this->modTSconfig['properties']['defLangBinding']));
         $configuration->setActiveColumns(GeneralUtility::trimExplode(',', $this->activeColPosList));
@@ -631,9 +632,6 @@ class PageLayoutController
         $configuration->setShowNewContentWizard(empty($this->modTSconfig['properties']['disableNewContentElementWizard']));
         $numberOfHiddenElements = $this->getNumberOfHiddenElements($configuration->getLanguageColumns());
 
-        $backendLayout = $this->backendLayouts->getBackendLayoutForPage((int)$this->id);
-        $backendLayout->setDrawingConfiguration($configuration);
-
         if (GeneralUtility::makeInstance(Features::class)->isFeatureEnabled('fluidBasedPageModule')) {
             $pageLayoutDrawer = $backendLayout->getBackendLayoutRenderer();
 
diff --git a/typo3/sysext/backend/Classes/View/BackendLayout/BackendLayout.php b/typo3/sysext/backend/Classes/View/BackendLayout/BackendLayout.php
index 5f83ebe133b5..053273c9cfc4 100644
--- a/typo3/sysext/backend/Classes/View/BackendLayout/BackendLayout.php
+++ b/typo3/sysext/backend/Classes/View/BackendLayout/BackendLayout.php
@@ -208,7 +208,7 @@ class BackendLayout
     public function setConfiguration($configuration)
     {
         $this->configuration = $configuration;
-        GeneralUtility::makeInstance(BackendLayoutView::class)->parseStructure($this);
+        $this->structure = GeneralUtility::makeInstance(BackendLayoutView::class)->parseStructure($this);
     }
 
     /**
diff --git a/typo3/sysext/backend/Classes/View/BackendLayoutView.php b/typo3/sysext/backend/Classes/View/BackendLayoutView.php
index 3895d9457ab7..02ba26912129 100644
--- a/typo3/sysext/backend/Classes/View/BackendLayoutView.php
+++ b/typo3/sysext/backend/Classes/View/BackendLayoutView.php
@@ -332,7 +332,7 @@ class BackendLayoutView implements \TYPO3\CMS\Core\SingletonInterface
      * @param int $pageId
      * @return array|null $backendLayout
      */
-    public function getSelectedBackendLayout($pageId): ?array
+    public function getSelectedBackendLayout($pageId)
     {
         $layout = $this->getBackendLayoutForPage((int)$pageId);
         if ($layout instanceof BackendLayout) {
@@ -362,11 +362,7 @@ class BackendLayoutView implements \TYPO3\CMS\Core\SingletonInterface
             $backendLayout = $this->getDataProviderCollection()->getBackendLayout('default', $pageId);
         }
 
-        $structure = null;
         if ($backendLayout instanceof BackendLayout) {
-            $structure = $this->parseStructure($backendLayout);
-            // Parse the configuration and inject it back in the backend layout object
-            $backendLayout->setStructure($structure);
             $this->selectedBackendLayout[$pageId] = $backendLayout;
         }
         return $backendLayout;
-- 
GitLab