Commit fc5a06e7 authored by Benni Mack's avatar Benni Mack Committed by Christian Kuhn
Browse files

[TASK] Simplify usages of LanguageService->sL

A few places still manually check for "LLL:" as
prefix. This is now resolved, as all of this is
already done in LanguageService directly.

Resolves: #96926
Releases: main
Change-Id: Icee5060a5d5b48177e9a5440fcab5d50e3dc9036
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/73561

Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
parent 35f7bbb3
......@@ -288,7 +288,7 @@ class ShortcutRepository
foreach ($bookmarkGroups as $groupId => $label) {
if (!empty($label)) {
$label = (string)$label;
$shortcutGroups[$groupId] = strpos($label, 'LLL:') === 0 ? $languageService->sL($label) : $label;
$shortcutGroups[$groupId] = $languageService->sL($label);
} elseif ($backendUser->isAdmin()) {
unset($shortcutGroups[$groupId]);
}
......
......@@ -50,17 +50,15 @@ class TcaInputPlaceholders implements FormDataProviderInterface
}
// Resolve __row|field type placeholders
if (strpos($fieldConfig['config']['placeholder'], '__row|') === 0) {
if (str_starts_with((string)$fieldConfig['config']['placeholder'], '__row|')) {
// split field names into array and remove the __row indicator
$fieldNameArray = array_slice(
GeneralUtility::trimExplode('|', $fieldConfig['config']['placeholder'], true),
1
);
$result['processedTca']['columns'][$fieldName]['config']['placeholder'] = $this->getPlaceholderValue($fieldNameArray, $result);
}
// Resolve placeholders from language files
if (strpos($fieldConfig['config']['placeholder'], 'LLL:') === 0) {
} elseif (!empty($fieldConfig['config']['placeholder'])) {
// Resolve placeholders from language files
$result['processedTca']['columns'][$fieldName]['config']['placeholder'] = $this->getLanguageService()->sL($fieldConfig['config']['placeholder']);
}
......
......@@ -505,11 +505,7 @@ class BackendLayoutView implements SingletonInterface
protected function getColumnName($column)
{
$columnName = $column['name'];
if (str_starts_with($columnName, 'LLL:')) {
$columnName = $this->getLanguageService()->sL($columnName);
}
$columnName = $this->getLanguageService()->sL($columnName);
return $columnName;
}
}
......@@ -17,6 +17,7 @@ declare(strict_types=1);
namespace TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use TYPO3\CMS\Backend\Form\FormDataCompiler;
use TYPO3\CMS\Backend\Form\FormDataProvider\TcaInputPlaceholders;
......@@ -31,6 +32,14 @@ class TcaInputPlaceholdersTest extends UnitTestCase
{
use ProphecyTrait;
protected function setUp(): void
{
parent::setUp();
$languageService = $this->prophesize(LanguageService::class);
$languageService->sL(Argument::cetera())->willReturnArgument(0);
$GLOBALS['LANG'] = $languageService->reveal();
}
/**
* @test
*/
......
......@@ -169,26 +169,27 @@ class LanguageService
if ($input === '') {
return $input;
}
// Use a constant non-localizable label
if (!str_starts_with(trim($input), 'LLL:')) {
return $input;
}
$cacheIdentifier = 'labels_' . md5($input . '_' . (int)$this->debugKey);
$cacheEntry = $this->runtimeCache->get($cacheIdentifier);
if ($cacheEntry !== false) {
return $cacheEntry;
}
if (strpos(trim($input), 'LLL:') === 0) {
$restStr = substr(trim($input), 4);
$extPrfx = '';
// ll-file referred to is found in an extension.
if (PathUtility::isExtensionPath(trim($restStr))) {
$restStr = substr(trim($restStr), 4);
$extPrfx = 'EXT:';
}
$parts = explode(':', trim($restStr));
$parts[0] = $extPrfx . $parts[0];
$output = $this->getLLL($parts[1] ?? '', $this->readLLfile($parts[0]));
} else {
// Use a constant non-localizable label
$output = $input;
// Remove the LLL: prefix
$restStr = substr(trim($input), 4);
$extensionPrefix = '';
// ll-file referred to is found in an extension
if (PathUtility::isExtensionPath(trim($restStr))) {
$restStr = substr(trim($restStr), 4);
$extensionPrefix = 'EXT:';
}
$parts = explode(':', trim($restStr));
$parts[0] = $extensionPrefix . $parts[0];
$output = $this->getLLL($parts[1] ?? '', $this->readLLfile($parts[0]));
$output .= $this->debugLL($input);
$this->runtimeCache->set($cacheIdentifier, $output);
return $output;
......
......@@ -91,9 +91,7 @@ final class CshViewHelper extends AbstractBackendViewHelper
$moduleName = $request->getPluginName();
$table = '_MOD_' . $moduleName;
}
if (strpos($label, 'LLL:') === 0) {
$label = self::getLanguageService()->sL($label);
}
$label = self::getLanguageService()->sL($label);
$label = '<label>' . htmlspecialchars($label, ENT_QUOTES, '', true) . '</label>';
return BackendUtility::wrapInHelp($table, $field, $label);
}
......
......@@ -1146,12 +1146,8 @@ class QueryGenerator
$fieldSetup = $conf;
$out = '';
if ($fieldSetup['type'] === 'multiple') {
foreach ($fieldSetup['items'] as $key => $val) {
if (strpos($val[0], 'LLL:') === 0) {
$value = $languageService->sL($val[0]);
} else {
$value = $val[0];
}
foreach ($fieldSetup['items'] as $val) {
$value = $languageService->sL($val[0]);
if (GeneralUtility::inList($fieldValue, $val[1]) || $fieldValue == $val[1]) {
if ($out !== '') {
$out .= $splitString;
......@@ -1161,12 +1157,8 @@ class QueryGenerator
}
}
if ($fieldSetup['type'] === 'binary') {
foreach ($fieldSetup['items'] as $Key => $val) {
if (strpos($val[0], 'LLL:') === 0) {
$value = $languageService->sL($val[0]);
} else {
$value = $val[0];
}
foreach ($fieldSetup['items'] as $val) {
$value = $languageService->sL($val[0]);
if ($out !== '') {
$out .= $splitString;
}
......@@ -1237,11 +1229,7 @@ class QueryGenerator
if (is_array($GLOBALS['TCA'][$from_table]['columns'][$labelField]['config']['items'] ?? false)) {
$items = $GLOBALS['TCA'][$from_table]['columns'][$labelField]['config']['items'];
foreach ($items as $labelArray) {
if (str_starts_with($labelArray[0], 'LLL:')) {
$labelFieldSelect[$labelArray[1]] = $languageService->sL($labelArray[0]);
} else {
$labelFieldSelect[$labelArray[1]] = $labelArray[0];
}
$labelFieldSelect[$labelArray[1]] = $languageService->sL($labelArray[0]);
}
$useSelectLabels = 1;
}
......@@ -1249,11 +1237,7 @@ class QueryGenerator
if (is_array($GLOBALS['TCA'][$from_table]['columns'][$altLabelField]['config']['items'] ?? false)) {
$items = $GLOBALS['TCA'][$from_table]['columns'][$altLabelField]['config']['items'];
foreach ($items as $altLabelArray) {
if (str_starts_with($altLabelArray[0], 'LLL:')) {
$altLabelFieldSelect[$altLabelArray[1]] = $languageService->sL($altLabelArray[0]);
} else {
$altLabelFieldSelect[$altLabelArray[1]] = $altLabelArray[0];
}
$altLabelFieldSelect[$altLabelArray[1]] = $languageService->sL($altLabelArray[0]);
}
$useAltSelectLabels = 1;
}
......@@ -1931,11 +1915,7 @@ class QueryGenerator
if ($fieldSetup['type'] === 'multiple') {
$optGroupOpen = false;
foreach (($fieldSetup['items'] ?? []) as $val) {
if (strpos($val[0], 'LLL:') === 0) {
$value = $languageService->sL($val[0]);
} else {
$value = $val[0];
}
$value = $languageService->sL($val[0]);
if ($val[1] === '--div--') {
if ($optGroupOpen) {
$out[] = '</optgroup>';
......@@ -1954,11 +1934,7 @@ class QueryGenerator
}
if ($fieldSetup['type'] === 'binary') {
foreach ($fieldSetup['items'] as $key => $val) {
if (strpos($val[0], 'LLL:') === 0) {
$value = $languageService->sL($val[0]);
} else {
$value = $val[0];
}
$value = $languageService->sL($val[0]);
if (GeneralUtility::inList($conf['inputValue'], (string)(2 ** $key))) {
$out[] = '<option value="' . 2 ** $key . '" selected>' . htmlspecialchars($value) . '</option>';
} else {
......@@ -1970,11 +1946,7 @@ class QueryGenerator
$useTablePrefix = 0;
$dontPrefixFirstTable = 0;
foreach (($fieldSetup['items'] ?? []) as $val) {
if (strpos($val[0], 'LLL:') === 0) {
$value = $languageService->sL($val[0]);
} else {
$value = $val[0];
}
$value = $languageService->sL($val[0]);
if (GeneralUtility::inList($conf['inputValue'], $val[1])) {
$out[] = '<option value="' . htmlspecialchars($val[1]) . '" selected>' . htmlspecialchars($value) . '</option>';
} else {
......@@ -2032,22 +2004,14 @@ class QueryGenerator
$altLabelField = $GLOBALS['TCA'][$from_table]['ctrl']['label_alt'] ?? '';
if ($GLOBALS['TCA'][$from_table]['columns'][$labelField]['config']['items'] ?? false) {
foreach ($GLOBALS['TCA'][$from_table]['columns'][$labelField]['config']['items'] as $labelArray) {
if (strpos($labelArray[0], 'LLL:') === 0) {
$labelFieldSelect[$labelArray[1]] = $languageService->sL($labelArray[0]);
} else {
$labelFieldSelect[$labelArray[1]] = $labelArray[0];
}
$labelFieldSelect[$labelArray[1]] = $languageService->sL($labelArray[0]);
}
$useSelectLabels = true;
}
$altLabelFieldSelect = [];
if ($GLOBALS['TCA'][$from_table]['columns'][$altLabelField]['config']['items'] ?? false) {
foreach ($GLOBALS['TCA'][$from_table]['columns'][$altLabelField]['config']['items'] as $altLabelArray) {
if (strpos($altLabelArray[0], 'LLL:') === 0) {
$altLabelFieldSelect[$altLabelArray[1]] = $languageService->sL($altLabelArray[0]);
} else {
$altLabelFieldSelect[$altLabelArray[1]] = $altLabelArray[0];
}
$altLabelFieldSelect[$altLabelArray[1]] = $languageService->sL($altLabelArray[0]);
}
$useAltSelectLabels = true;
}
......
......@@ -434,11 +434,7 @@ class RecordListController
{
$languageService = $this->getLanguageService();
if ($singleTable && isset($GLOBALS['TCA'][$singleTable]['ctrl']['title'])) {
if (str_starts_with($GLOBALS['TCA'][$singleTable]['ctrl']['title'], 'LLL:')) {
$message = sprintf($languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf:noRecordsOfTypeOnThisPage'), $languageService->sL($GLOBALS['TCA'][$singleTable]['ctrl']['title']));
} else {
$message = sprintf($languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf:noRecordsOfTypeOnThisPage'), $GLOBALS['TCA'][$singleTable]['ctrl']['title']);
}
$message = sprintf($languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf:noRecordsOfTypeOnThisPage'), $languageService->sL($GLOBALS['TCA'][$singleTable]['ctrl']['title']));
} else {
$message = $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf:noRecordsOnThisPage');
}
......
......@@ -194,7 +194,7 @@ class Status implements RequestAwareReportInterface
// @todo extract into getLabel() method
$secondaryStatuses = [];
foreach ($statusCollection as $statusProviderId => $collection) {
if (strpos($statusProviderId, 'LLL:') === 0) {
if (str_starts_with($statusProviderId, 'LLL:')) {
// Label provided by extension
$label = $this->getLanguageService()->sL($statusProviderId);
} else {
......
......@@ -246,11 +246,7 @@ class BrowseLinksController extends AbstractLinkBrowserController
*/
protected function getPageConfigLabel(string $string, bool $JScharCode = true): string
{
if (!str_starts_with($string, 'LLL:')) {
$label = $string;
} else {
$label = $this->getLanguageService()->sL(trim($string));
}
$label = $this->getLanguageService()->sL(trim($string));
$label = str_replace(['\\\'', '"'], ['\'', '\\"'], $label);
return $JScharCode ? GeneralUtility::quoteJSvalue($label) : $label;
}
......
......@@ -296,7 +296,7 @@ class RichTextElement extends AbstractFormElement
foreach ($configuration as $key => $value) {
if (is_array($value)) {
$configuration[$key] = $this->replaceLanguageFileReferences($value);
} elseif (is_string($value) && stripos($value, 'LLL:') === 0) {
} elseif (is_string($value)) {
$configuration[$key] = $this->getLanguageService()->sL($value);
}
}
......
......@@ -654,11 +654,7 @@ class SetupModuleController
*/
protected function getLabel($str, $key = '', $addLabelTag = true)
{
if (strpos($str, 'LLL:') === 0) {
$out = htmlspecialchars($this->getLanguageService()->sL($str));
} else {
$out = htmlspecialchars($str);
}
$out = htmlspecialchars($this->getLanguageService()->sL($str));
if (isset($this->overrideConf[$key ?: $str])) {
$out = '<span style="color:#999999">' . $out . '</span>';
}
......
......@@ -210,7 +210,7 @@ class ViewModuleController
}
if (!isset($data['label'])) {
$data['label'] = $data['key'];
} elseif (strpos($data['label'], 'LLL:') === 0) {
} else {
$data['label'] = $this->getLanguageService()->sL(trim($data['label']));
}
......
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