From 332ed405b9a1948a9768653454e4f02864c6fc32 Mon Sep 17 00:00:00 2001
From: Philipp Kitzberger <philipp@cron-it.de>
Date: Tue, 11 Oct 2016 21:09:29 +0000
Subject: [PATCH] [FEATURE] Display (un)substituted TS constant

Display value of TS constants on "UN-substituted constants in green"
mode and constant name when on "Substituted constant in green" mode.

Before this patch toggling between both modes was necessary to simply
get an idea of what the value/variable name was while being on the
'other' mode.

As a side effect this patch improves the search feature of the object
browser when searching for a constant value or name, i.e. 'maxWInText'
while being on "Substituted" mode.

Resolves: #40729
Releases: master
Change-Id: Ic8c3f1b96b3b440a3ed4d098604e29d018129451
Reviewed-on: https://review.typo3.org/50190
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
---
 .../TypoScript/ExtendedTemplateService.php    | 15 +++++-----
 ...nsubstitutedConstantsInTSObjectBrowser.rst | 28 +++++++++++++++++++
 ...eObjectBrowserModuleFunctionController.php |  3 +-
 3 files changed, 38 insertions(+), 8 deletions(-)
 create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Feature-40729-TitleAttributeForUnsubstitutedConstantsInTSObjectBrowser.rst

diff --git a/typo3/sysext/core/Classes/TypoScript/ExtendedTemplateService.php b/typo3/sysext/core/Classes/TypoScript/ExtendedTemplateService.php
index e7a45c2c105f..92faef10e8ba 100644
--- a/typo3/sysext/core/Classes/TypoScript/ExtendedTemplateService.php
+++ b/typo3/sysext/core/Classes/TypoScript/ExtendedTemplateService.php
@@ -274,10 +274,10 @@ class ExtendedTemplateService extends TemplateService
         $marker = substr(md5($matches[0]), 0, 6);
         switch ($this->constantMode) {
             case 'const':
-                $ret_val = isset($this->flatSetup[$matches[1]]) && !is_array($this->flatSetup[$matches[1]]) ? '##' . $marker . '_B##' . $matches[0] . '##' . $marker . '_E##' : $matches[0];
+                $ret_val = isset($this->flatSetup[$matches[1]]) && !is_array($this->flatSetup[$matches[1]]) ? '##' . $marker . '_B##' . $this->flatSetup[$matches[1]] . '##' . $marker . '_M##' . $matches[0] . '##' . $marker . '_E##' : $matches[0];
                 break;
             case 'subst':
-                $ret_val = isset($this->flatSetup[$matches[1]]) && !is_array($this->flatSetup[$matches[1]]) ? '##' . $marker . '_B##' . $this->flatSetup[$matches[1]] . '##' . $marker . '_E##' : $matches[0];
+                $ret_val = isset($this->flatSetup[$matches[1]]) && !is_array($this->flatSetup[$matches[1]]) ? '##' . $marker . '_B##' . $matches[0] . '##' . $marker . '_M##' . $this->flatSetup[$matches[1]] . '##' . $marker . '_E##' : $matches[0];
                 break;
             case 'untouched':
                 $ret_val = $matches[0];
@@ -289,7 +289,8 @@ class ExtendedTemplateService extends TemplateService
     }
 
     /**
-     * Substitute markers
+     * Substitute markers added in substituteConstantsCallBack()
+     * with ##6chars_B##value1##6chars_M##value2##6chars_E##
      *
      * @param string $all
      * @return string
@@ -300,9 +301,9 @@ class ExtendedTemplateService extends TemplateService
             case 'const':
             case 'subst':
                 $all = preg_replace(
-                    '/##[a-z0-9]{6}_B##((?:(?!##[a-z0-9]{6}_E##).)+)?##[a-z0-9]{6}_E##/',
-                        '<strong style="color: green;">$1</strong>',
-                        $all
+                    '/##[a-z0-9]{6}_B##(.*?)##[a-z0-9]{6}_M##(.*?)##[a-z0-9]{6}_E##/',
+                    '<strong class="text-success" data-toggle="tooltip" data-placement="top" data-title="$1" title="$1">$2</strong>',
+                    $all
                 );
                 break;
             default:
@@ -312,7 +313,7 @@ class ExtendedTemplateService extends TemplateService
 
     /**
      * Parse constants with respect to the constant-editor in this module.
-     * In particular comments in the code are registered.
+     * In particular comments in the code are registered and the edit_divider is taken into account.
      *
      * @return array
      */
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-40729-TitleAttributeForUnsubstitutedConstantsInTSObjectBrowser.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-40729-TitleAttributeForUnsubstitutedConstantsInTSObjectBrowser.rst
new file mode 100644
index 000000000000..160af30376d0
--- /dev/null
+++ b/typo3/sysext/core/Documentation/Changelog/master/Feature-40729-TitleAttributeForUnsubstitutedConstantsInTSObjectBrowser.rst
@@ -0,0 +1,28 @@
+.. include:: ../../Includes.txt
+
+====================================================================================
+Feature: #40729 - Title attribute for (un)substituted constants in TS object browser
+====================================================================================
+
+See :issue:`40729`
+
+Description
+===========
+
+The TypoScript object browser Backend Module comes now with a tiny improvement for
+the "(un)substituted constants" view.
+When hovering over an item in the object browser, the constant name will be shown when in
+"substituted constants in green" mode, or the constant value when in "unsubstituted constants in
+green" mode.
+
+This way one doesn't necessarily have to toggle between the two "green modes".
+
+
+Impact
+======
+
+Less toggling between the two "contants in green" modes while using the TS object browser.
+And as a side effect this patch improves the search feature of the object browser when searching
+for a constant value or name, i.e. 'maxWInText' while being on "substituted" mode.
+
+.. index:: Backend, TypoScript
diff --git a/typo3/sysext/tstemplate/Classes/Controller/TypoScriptTemplateObjectBrowserModuleFunctionController.php b/typo3/sysext/tstemplate/Classes/Controller/TypoScriptTemplateObjectBrowserModuleFunctionController.php
index 7db4bdbc0e5d..e556f6cb6d95 100644
--- a/typo3/sysext/tstemplate/Classes/Controller/TypoScriptTemplateObjectBrowserModuleFunctionController.php
+++ b/typo3/sysext/tstemplate/Classes/Controller/TypoScriptTemplateObjectBrowserModuleFunctionController.php
@@ -377,7 +377,8 @@ class TypoScriptTemplateObjectBrowserModuleFunctionController extends AbstractFu
             }
             // Ending section displayoptions
         }
-
+        $this->getPageRenderer();
+        $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Tooltip');
         $view = GeneralUtility::makeInstance(StandaloneView::class);
         $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
             'EXT:tstemplate/Resources/Private/Templates/TemplateObjectBrowserModuleFunction.html'
-- 
GitLab