From 9773f7b9d7844bd3e5509d1a284df7fb1ca77d32 Mon Sep 17 00:00:00 2001
From: Jochen Roth <jochen.roth@b13.com>
Date: Wed, 23 Jun 2021 16:35:56 +0200
Subject: [PATCH] [BUGFIX] Undefined array key in ElementInformation

A click on inline fal ElementInformation button leads to
Undefined array key "returnUrl".
Fixed by adding empty string as fallback and add an
acceptance test to make sure it will not appear again.

Resolves: #94400
Releases: master
Change-Id: I7e44b026f81b0d484e3b8a1af5522fece228d5d4
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/69544
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
---
 .../ElementInformationController.php          |  2 +-
 .../Backend/FormEngine/InlineFalCest.php      | 98 +++++++++++++++++++
 2 files changed, 99 insertions(+), 1 deletion(-)
 create mode 100644 typo3/sysext/core/Tests/Acceptance/Backend/FormEngine/InlineFalCest.php

diff --git a/typo3/sysext/backend/Classes/Controller/ContentElement/ElementInformationController.php b/typo3/sysext/backend/Classes/Controller/ContentElement/ElementInformationController.php
index 4cd55c9b8f14..e6c225c41a78 100644
--- a/typo3/sysext/backend/Classes/Controller/ContentElement/ElementInformationController.php
+++ b/typo3/sysext/backend/Classes/Controller/ContentElement/ElementInformationController.php
@@ -259,7 +259,7 @@ class ElementInformationController
                 $view->assignMultiple($this->getPreview());
                 $view->assignMultiple($this->getPropertiesForTable());
                 $view->assignMultiple($this->getReferences($request));
-                $view->assign('returnUrl', GeneralUtility::sanitizeLocalUrl($request->getQueryParams()['returnUrl']));
+                $view->assign('returnUrl', GeneralUtility::sanitizeLocalUrl($request->getQueryParams()['returnUrl'] ?? ''));
                 $view->assign('maxTitleLength', $this->getBackendUser()->uc['titleLen'] ?? 20);
                 $content .= $view->render();
             }
diff --git a/typo3/sysext/core/Tests/Acceptance/Backend/FormEngine/InlineFalCest.php b/typo3/sysext/core/Tests/Acceptance/Backend/FormEngine/InlineFalCest.php
new file mode 100644
index 000000000000..f13e90c49527
--- /dev/null
+++ b/typo3/sysext/core/Tests/Acceptance/Backend/FormEngine/InlineFalCest.php
@@ -0,0 +1,98 @@
+<?php
+
+declare(strict_types=1);
+
+/*
+ * 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!
+ */
+
+namespace TYPO3\CMS\Core\Tests\Acceptance\Backend\FormEngine;
+
+use TYPO3\CMS\Core\Tests\Acceptance\Support\BackendTester;
+use TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\ModalDialog;
+use TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\PageTree;
+
+/**
+ * Tests for inline fal
+ */
+class InlineFalCest
+{
+    protected static string $filenameSelector = '.tab-content .form-irre-header-cell .form-irre-header-body dd';
+    protected static string $saveButtonLink = '//*/button[@name="_savedok"][1]';
+
+    /**
+     * Open styleguide inline fal page in list module
+     *
+     * @param BackendTester $I
+     * @param PageTree $pageTree
+     * @throws \Exception
+     */
+    public function _before(BackendTester $I, PageTree $pageTree)
+    {
+        $I->useExistingSession('admin');
+
+        $I->click('List');
+        $I->waitForElement('svg .nodes .node');
+        $pageTree->openPath(['styleguide TCA demo', 'inline fal']);
+        $I->switchToContentFrame();
+
+        $I->waitForText('inline fal', 20);
+        $editRecordLinkCssPath = '#recordlist-tx_styleguide_inline_fal a[data-bs-original-title="Edit record"]';
+        $I->click($editRecordLinkCssPath);
+        $I->waitForText('Edit Form', 3, 'h1');
+    }
+
+    /**
+     * @param BackendTester $I
+     * @param ModalDialog $modalDialog
+     */
+    public function seeFalRelationInfo(BackendTester $I, ModalDialog $modalDialog)
+    {
+        $infoButtonSelector = '.tab-content button[data-action="infowindow"]';
+
+        $filename = $I->grabTextFrom(self::$filenameSelector);
+        $I->click($infoButtonSelector);
+        $modalDialog->canSeeDialog();
+        $I->switchToIFrame('.modal-iframe');
+        $modalTitle = $I->grabTextFrom('.card-title');
+        $I->assertContains($filename, $modalTitle);
+    }
+
+    /**
+     * @param BackendTester $I
+     */
+    public function hideFalRelation(BackendTester $I)
+    {
+        $hideButtonSelector = '.tab-content .t3js-toggle-visibility-button';
+
+        $I->click($hideButtonSelector);
+        $I->click(self::$saveButtonLink);
+        $I->seeElement('.tab-content .t3-form-field-container-inline-hidden');
+    }
+
+    /**
+     * @param BackendTester $I
+     * @param ModalDialog $modalDialog
+     */
+    public function deleteFalRelation(BackendTester $I, ModalDialog $modalDialog)
+    {
+        $deleteButtonSelector = '.tab-content .t3js-editform-delete-inline-record';
+        $filename = $I->grabTextFrom(self::$filenameSelector);
+
+        $I->click($deleteButtonSelector);
+        $modalDialog->canSeeDialog();
+        $I->click('button[name="yes"]', ModalDialog::$openedModalButtonContainerSelector);
+        $I->switchToContentFrame();
+        $I->click(self::$saveButtonLink);
+        $I->dontSee($filename, '.tab-content .form-section:first-child');
+    }
+}
-- 
GitLab