From eb2ac1f1abafb4bf305390607a4598072c151b2c Mon Sep 17 00:00:00 2001
From: Georg Ringer <georg.ringer@gmail.com>
Date: Wed, 3 Jan 2018 20:21:29 +0100
Subject: [PATCH] [FEATURE] Show the field name for every FormEngine field if
 debug is enabled

Improve the life of integrators and developers by showing the field name
next to the title.

Resolves: #83461
Releases: master
Change-Id: I100022fb33facefe5f70cf99c2304fb080361427
Reviewed-on: https://review.typo3.org/55254
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
---
 .../Container/PaletteAndSingleContainer.php   | 15 +++++++++++++
 .../PaletteAndSingleContainerTest.php         |  7 ++++++
 .../DefaultConfigurationDescription.yaml      |  2 +-
 ...61-ShowFieldnameNextToTitleInDebugMode.rst | 22 +++++++++++++++++++
 4 files changed, 45 insertions(+), 1 deletion(-)
 create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Feature-83461-ShowFieldnameNextToTitleInDebugMode.rst

diff --git a/typo3/sysext/backend/Classes/Form/Container/PaletteAndSingleContainer.php b/typo3/sysext/backend/Classes/Form/Container/PaletteAndSingleContainer.php
index 2e7daf9eb496..43af13dfae64 100644
--- a/typo3/sysext/backend/Classes/Form/Container/PaletteAndSingleContainer.php
+++ b/typo3/sysext/backend/Classes/Form/Container/PaletteAndSingleContainer.php
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Backend\Form\Container;
  */
 
 use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
 use TYPO3\CMS\Core\Localization\LanguageService;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
@@ -377,6 +378,10 @@ class PaletteAndSingleContainer extends AbstractContainer
 
         $label = BackendUtility::wrapInHelp($this->data['tableName'], $fieldName, htmlspecialchars($element['fieldLabel']));
 
+        if ($GLOBALS['TYPO3_CONF_VARS']['BE']['debug'] && $this->getBackendUser()->isAdmin()) {
+            $label .= '<code>[' . htmlspecialchars($fieldName) . ']</code>';
+        }
+
         $content = [];
         $content[] = '<div class="' . implode(' ', $paletteFieldClasses) . '">';
         $content[] =    '<label class="t3js-formengine-label">';
@@ -413,4 +418,14 @@ class PaletteAndSingleContainer extends AbstractContainer
     {
         return $GLOBALS['LANG'];
     }
+
+    /**
+     * Returns the current BE user.
+     *
+     * @return BackendUserAuthentication
+     */
+    protected function getBackendUser()
+    {
+        return $GLOBALS['BE_USER'];
+    }
 }
diff --git a/typo3/sysext/backend/Tests/Unit/Form/Container/PaletteAndSingleContainerTest.php b/typo3/sysext/backend/Tests/Unit/Form/Container/PaletteAndSingleContainerTest.php
index 778eb29adcc5..430feeaaa2ad 100644
--- a/typo3/sysext/backend/Tests/Unit/Form/Container/PaletteAndSingleContainerTest.php
+++ b/typo3/sysext/backend/Tests/Unit/Form/Container/PaletteAndSingleContainerTest.php
@@ -19,6 +19,7 @@ use Prophecy\Argument;
 use TYPO3\CMS\Backend\Form\Container\PaletteAndSingleContainer;
 use TYPO3\CMS\Backend\Form\Container\SingleFieldContainer;
 use TYPO3\CMS\Backend\Form\NodeFactory;
+use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
 use TYPO3\CMS\Core\Localization\LanguageService;
 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
 
@@ -66,6 +67,8 @@ class PaletteAndSingleContainerTest extends UnitTestCase
 
         $languageService = $this->prophesize(LanguageService::class);
         $GLOBALS['LANG'] = $languageService->reveal();
+        $backendUserAuthentication = $this->prophesize(BackendUserAuthentication::class);
+        $GLOBALS['BE_USER'] = $backendUserAuthentication->reveal();
         $languageService->loadSingleTableDescription(Argument::cetera())->willReturn('');
 
         // Expect translation call to the label reference
@@ -121,6 +124,8 @@ class PaletteAndSingleContainerTest extends UnitTestCase
 
         $languageService = $this->prophesize(LanguageService::class);
         $GLOBALS['LANG'] = $languageService->reveal();
+        $backendUserAuthentication = $this->prophesize(BackendUserAuthentication::class);
+        $GLOBALS['BE_USER'] = $backendUserAuthentication->reveal();
         $languageService->loadSingleTableDescription(Argument::cetera())->willReturn('');
 
         // Expect translation call to the label reference
@@ -177,6 +182,8 @@ class PaletteAndSingleContainerTest extends UnitTestCase
 
         $languageService = $this->prophesize(LanguageService::class);
         $GLOBALS['LANG'] = $languageService->reveal();
+        $backendUserAuthentication = $this->prophesize(BackendUserAuthentication::class);
+        $GLOBALS['BE_USER'] = $backendUserAuthentication->reveal();
         $languageService->loadSingleTableDescription(Argument::cetera())->willReturn('');
 
         // Expect translation call to the label reference
diff --git a/typo3/sysext/core/Configuration/DefaultConfigurationDescription.yaml b/typo3/sysext/core/Configuration/DefaultConfigurationDescription.yaml
index 37b71744e6b8..fbd48ad5a3d4 100644
--- a/typo3/sysext/core/Configuration/DefaultConfigurationDescription.yaml
+++ b/typo3/sysext/core/Configuration/DefaultConfigurationDescription.yaml
@@ -334,7 +334,7 @@ BE:
               <p>If disabled the last modification date of the file will be appended as a query-string.</p>
         debug:
             type: bool
-            description: 'If enabled, the loginrefresh is disabled and pageRenderer is set to debug mode. Use this to debug the backend only!'
+            description: 'If enabled, the loginrefresh is disabled and pageRenderer is set to debug mode. Furthermore the fieldname is prepended to the label of fields. Use this to debug the backend only!'
 FE:
     type: container
     items:
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-83461-ShowFieldnameNextToTitleInDebugMode.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-83461-ShowFieldnameNextToTitleInDebugMode.rst
new file mode 100644
index 000000000000..8be1f665c408
--- /dev/null
+++ b/typo3/sysext/core/Documentation/Changelog/master/Feature-83461-ShowFieldnameNextToTitleInDebugMode.rst
@@ -0,0 +1,22 @@
+.. include:: ../../Includes.txt
+
+============================================================
+Feature: #83461 - Show fieldname next to title in debug mode
+============================================================
+
+See :issue:`83461`
+
+Description
+===========
+
+If the configuration `['BE']['debug']` is enabled and the current user is an administrator, the fieldname is prepended to the title of each field generated by the `FormEngine`.
+
+
+Impact
+======
+
+The correct name of a field is important to know for developers and integrators. Examples are setting up access permissions or configuration using TsConfig.
+
+Instead of looking into the source code of the browser, it is now enough to enable the debug mode for the backend.
+
+.. index:: Backend, NotScanned
-- 
GitLab