Commit a9b2298d authored by Georg Ringer's avatar Georg Ringer Committed by Frank Nägler
Browse files

[FEATURE] Show value of fields in debug mode

If the configuration `['BE']['debug']` is enabled and the current user is an administrator,
the value of select, radio and checkbox fields which are generated by
the `FormEngine` is appended to its label.

Resolves: #83748
Releases: master
Change-Id: I735bd3c83b5b12eb3cddcc66d1b92d48cf5e5991
Reviewed-on: https://review.typo3.org/56147


Tested-by: default avatarTYPO3com <no-reply@typo3.com>
Reviewed-by: Susanne Moog's avatarSusanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog's avatarSusanne Moog <susanne.moog@typo3.org>
Reviewed-by: Frank Nägler's avatarFrank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Nägler's avatarFrank Naegler <frank.naegler@typo3.org>
parent 32123cf0
......@@ -17,6 +17,7 @@ namespace TYPO3\CMS\Backend\Form\Element;
use TYPO3\CMS\Backend\Form\AbstractNode;
use TYPO3\CMS\Backend\Form\NodeFactory;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Utility\ArrayUtility;
......@@ -370,6 +371,22 @@ abstract class AbstractFormElement extends AbstractNode
return [$colClass, $colClear];
}
/**
* Append the value of a form field to its label
*
* @param string|int $label The label which can also be an integer
* @param string|int $value The value which can also be an integer
* @return string|int
*/
protected function appendValueToLabelInDebugMode($label, $value)
{
if ($value !== '' && $GLOBALS['TYPO3_CONF_VARS']['BE']['debug'] && $this->getBackendUser()->isAdmin()) {
return $label . ' [' . $value . ']';
}
return $label;
}
/**
* @return LanguageService
*/
......@@ -377,4 +394,14 @@ abstract class AbstractFormElement extends AbstractNode
{
return $GLOBALS['LANG'];
}
/**
* Returns the current BE user.
*
* @return BackendUserAuthentication
*/
protected function getBackendUser()
{
return $GLOBALS['BE_USER'];
}
}
......@@ -199,7 +199,7 @@ class CheckboxElement extends AbstractFormElement
<span class="checkbox-label-icon-checked">' . ($invert ? $iconUnchecked : $iconChecked) . '</span>
<span class="checkbox-label-icon-unchecked">' . ($invert ? $iconChecked : $iconUnchecked) . '</span>
</span>
<span class="checkbox-label-text">' . ($label ? htmlspecialchars($label) : '&nbsp;') . '</span>
<span class="checkbox-label-text">' . $this->appendValueToLabelInDebugMode(($label ? htmlspecialchars($label) : '&nbsp;'), $formElementValue) . '</span>
</label>
</div>';
}
......
......@@ -190,7 +190,7 @@ class CheckboxLabeledToggleElement extends AbstractFormElement
' . $config['items'][$itemCounter]['labelUnchecked'] . '
</span>
</span>
<span class="checkbox-label-text">' . ($label ? htmlspecialchars($label) : '&nbsp;') . '</span>
<span class="checkbox-label-text">' . $this->appendValueToLabelInDebugMode(($label ? htmlspecialchars($label) : '&nbsp;'), $formElementValue) . '</span>
</label>
</div>';
}
......
......@@ -182,7 +182,7 @@ class CheckboxToggleElement extends AbstractFormElement
' . (!$disabled ?: ' disabled="disabled"') . '
id="' . $checkboxId . '" />
<label class="checkbox-label" for="' . $checkboxId . '">
<span class="checkbox-label-text">' . ($label ? htmlspecialchars($label) : '&nbsp;') . '</span>
<span class="checkbox-label-text">' . $this->appendValueToLabelInDebugMode(($label ? htmlspecialchars($label) : '&nbsp;'), $formElementValue) . '</span>
</label>
</div>';
}
......
......@@ -142,7 +142,7 @@ class GroupElement extends AbstractFormElement
$shortenedTitle = GeneralUtility::fixed_lgd_cs($title, $maxTitleLength);
$selectorOptionsHtml[] =
'<option value="' . htmlspecialchars($uidOrPath) . '" title="' . htmlspecialchars($title) . '">'
. htmlspecialchars($shortenedTitle)
. htmlspecialchars($this->appendValueToLabelInDebugMode($shortenedTitle, $uidOrPath))
. '</option>';
}
} elseif ($internalType === 'folder') {
......@@ -165,7 +165,7 @@ class GroupElement extends AbstractFormElement
$shortenedTitle = GeneralUtility::fixed_lgd_cs($title, $maxTitleLength);
$selectorOptionsHtml[] =
'<option value="' . htmlspecialchars($tableWithUid) . '" title="' . htmlspecialchars($title) . '">'
. htmlspecialchars($shortenedTitle)
. htmlspecialchars($this->appendValueToLabelInDebugMode($shortenedTitle, $tableWithUid))
. '</option>';
}
} else {
......
......@@ -87,7 +87,7 @@ class RadioElement extends AbstractFormElement
$html[] = $disabled;
$html[] = ' onclick="' . htmlspecialchars(implode('', $this->data['parameterArray']['fieldChangeFunc'])) . '"';
$html[] = '/>';
$html[] = htmlspecialchars($label);
$html[] = htmlspecialchars($this->appendValueToLabelInDebugMode($label, $value));
$html[] = '</label>';
$html[] = '</div>';
$html[] = '</div>';
......
......@@ -186,7 +186,7 @@ class SelectCheckBoxElement extends AbstractFormElement
$tableRows[] = '<label class="label-block" for="' . $item['id'] . '">' . $item['icon'] . '</label>';
$tableRows[] = '</td>';
$tableRows[] = '<td class="col-title">';
$tableRows[] = '<label class="label-block" for="' . $item['id'] . '">' . htmlspecialchars($item['title'], ENT_COMPAT, 'UTF-8', false) . '</label>';
$tableRows[] = '<label class="label-block" for="' . $item['id'] . '">' . htmlspecialchars($this->appendValueToLabelInDebugMode($item['title'], $item['value']), ENT_COMPAT, 'UTF-8', false) . '</label>';
$tableRows[] = '</td>';
$tableRows[] = '<td class="text-right">' . $item['help'] . '</td>';
$tableRows[] = '</tr>';
......
......@@ -114,7 +114,7 @@ class SelectMultipleSideBySideElement extends AbstractFormElement
if ($possibleItem[1] == $itemValue) {
$title = $possibleItem[0];
$listOfSelectedValues[] = $itemValue;
$selectedItemsHtml[] = '<option value="' . htmlspecialchars($itemValue) . '" title="' . htmlspecialchars($title) . '">' . htmlspecialchars($title) . '</option>';
$selectedItemsHtml[] = '<option value="' . htmlspecialchars($itemValue) . '" title="' . htmlspecialchars($title) . '">' . htmlspecialchars($this->appendValueToLabelInDebugMode($title, $itemValue)) . '</option>';
break;
}
}
......@@ -134,7 +134,7 @@ class SelectMultipleSideBySideElement extends AbstractFormElement
. '" title="' . htmlspecialchars($possibleItem[0]) . '"'
. $classAttr . $disabledAttr
. '>'
. htmlspecialchars($possibleItem[0]) .
. htmlspecialchars($this->appendValueToLabelInDebugMode($possibleItem[0], $possibleItem[1])) .
'</option>';
}
......
......@@ -202,7 +202,7 @@ class SelectSingleBoxElement extends AbstractFormElement
$attributes['value'] = $value;
$html = [
'<option ' . GeneralUtility::implodeAttributes($attributes, true) . '>',
htmlspecialchars($label, ENT_COMPAT, 'UTF-8', false),
htmlspecialchars($this->appendValueToLabelInDebugMode($label, $value), ENT_COMPAT, 'UTF-8', false),
'</option>'
];
......
......@@ -140,7 +140,7 @@ class SelectSingleElement extends AbstractFormElement
}
$selectItemGroups[$selectItemGroupCount]['items'][] = [
'title' => $item[0],
'title' => $this->appendValueToLabelInDebugMode($item[0], $item[1]),
'value' => $item[1],
'icon' => $icon,
'selected' => $selected,
......
......@@ -277,7 +277,7 @@ abstract class AbstractItemProvider
foreach ($result['systemLanguageRows'] as $language) {
if ($language['uid'] !== -1) {
$items[] = [
0 => $language['title'] . ' [' . $language['uid'] . ']',
0 => $language['title'],
1 => $language['uid'],
2 => $language['flagIconIdentifier']
];
......
......@@ -1058,7 +1058,7 @@ class TcaSelectItemsTest extends UnitTestCase
$expectedItems = [
0 => [
0 => 'aLangTitle [42]',
0 => 'aLangTitle',
1 => 42,
2 => 'aFlag.gif',
3 => null,
......
.. include:: ../../Includes.txt
====================================================
Feature: #83748 - Show value of fields in debug mode
====================================================
See :issue:`83748`
Description
===========
If the configuration :php:`$GLOBALS['TYPO3_CONF_VARS']['BE']['debug']` is enabled and the current user is an administrator, the value of select, radio and checkbox fields which are generated by the :php:`FormEngine` is appended to its label.
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 possible to display those name by enabling the debug
mode for the backend.
.. index:: Backend
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment