2 declare(strict_types
=1);
3 namespace TYPO3\CMS\Backend\Form\FieldWizard
;
6 * This file is part of the TYPO3 CMS project.
8 * It is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, either version 2
10 * of the License, or any later version.
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
15 * The TYPO3 project - inspiring people to share!
18 use TYPO3\CMS\Backend\Form\AbstractNode
;
19 use TYPO3\CMS\Core\DataHandling\Localization\State
;
20 use TYPO3\CMS\Lang\LanguageService
;
23 * Allows to define the localization state per field.
25 class LocalizationStateSelector
extends AbstractNode
28 * Render the radio buttons if enabled
30 * @return array Result array
32 public function render(): array
34 $languageService = $this->getLanguageService();
35 $result = $this->initializeResultArray();
37 $fieldName = $this->data
['fieldName'];
38 $l10nStateFieldName = '';
39 if (isset($l10nStateFieldName)) {
40 $l10nStateFieldName = 'l10n_state';
44 ||
!isset($this->data
['defaultLanguageRow'])
45 ||
!isset($this->data
['processedTca']['columns'][$fieldName]['config']['behaviour']['allowLanguageSynchronization'])
46 ||
!$this->data
['processedTca']['columns'][$fieldName]['config']['behaviour']['allowLanguageSynchronization']
51 $l10nParentFieldName = $this->data
['processedTca']['ctrl']['transOrigPointerField'] ??
null;
52 $l10nSourceFieldName = $this->data
['processedTca']['ctrl']['translationSource'] ??
null;
54 $sourceLanguageTitle = '';
55 $fieldValueInParentRow = '';
56 $fieldValueInSourceRow = null;
57 if ($l10nParentFieldName && $this->data
['databaseRow'][$l10nParentFieldName] > 0) {
58 if ($l10nSourceFieldName && $this->data
['databaseRow'][$l10nSourceFieldName] > 0) {
59 $languageField = $this->data
['processedTca']['ctrl']['languageField'] ??
null;
61 && isset($this->data
['sourceLanguageRow'][$languageField])
62 && $this->data
['sourceLanguageRow'][$languageField] > 0
64 $languageUidOfSourceRow = $this->data
['sourceLanguageRow'][$languageField];
65 $sourceLanguageTitle = $this->data
['systemLanguageRows'][$languageUidOfSourceRow]['title'] ??
'';
66 $fieldValueInSourceRow = $this->data
['sourceLanguageRow'][$fieldName] ??
null;
69 $fieldValueInParentRow = (string)$this->data
['defaultLanguageRow'][$fieldName];
72 $localizationState = State
::fromJSON(
73 $this->data
['tableName'],
74 $this->data
['databaseRow'][$l10nStateFieldName] ??
null
77 $fieldElementName = 'data[' . htmlspecialchars($this->data
['tableName']) . ']'
78 . '[' . (int)($this->data
['databaseRow']['uid']) . ']'
79 . '[' . htmlspecialchars($l10nStateFieldName) . ']'
80 . '[' . htmlspecialchars($this->data
['fieldName']) . ']';
83 $html[] = '<div class="t3js-l10n-state-container">';
86 $html[] = $languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_wizards.xlf:localizationStateSelector.header');
87 $html[] = '</strong>';
89 $html[] = '<div class="radio radio-inline">';
92 $html[] = ' type="radio"';
93 $html[] = ' name="' . htmlspecialchars($fieldElementName) . '"';
94 $html[] = ' class="t3js-l10n-state-custom"';
95 $html[] = ' value="custom"';
96 $html[] = $localizationState->isCustomState($fieldName) ?
' checked="checked"' : '';
97 $html[] = ' data-original-language-value=""';
99 $html[] = $languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_wizards.xlf:localizationStateSelector.customValue');
100 $html[] = '</label>';
102 $html[] = '<div class="radio radio-inline">';
105 $html[] = ' type="radio"';
106 $html[] = ' name="' . htmlspecialchars($fieldElementName) . '"';
107 $html[] = ' value="parent"';
108 $html[] = $localizationState->isParentState($fieldName) ?
' checked="checked"' : '';
109 $html[] = ' data-original-language-value="' . htmlspecialchars((string)$fieldValueInParentRow) . '"';
111 $html[] = $languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_wizards.xlf:localizationStateSelector.defaultLanguageValue');
112 $html[] = '</label>';
114 if ($fieldValueInSourceRow !== null) {
115 $html[] = '<div class="radio radio-inline">';
118 $html[] = ' type="radio"';
119 $html[] = ' name="' . htmlspecialchars($fieldElementName) . '"';
120 $html[] = ' value="source"';
121 $html[] = $localizationState->isSourceState($fieldName) ?
' checked="checked"' : '';
122 $html[] = ' data-original-language-value="' . htmlspecialchars((string)$fieldValueInSourceRow) . '"';
124 $html[] = sprintf($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_wizards.xlf:localizationStateSelector.sourceLanguageValue'), htmlspecialchars($sourceLanguageTitle));
125 $html[] = '</label>';
130 $result['html'] = implode(LF
, $html);
135 * @return LanguageService
137 protected function getLanguageService()
139 return $GLOBALS['LANG'];