‪TYPO3CMS  ‪main
LocalizationStateSelector.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
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.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
25 
30 {
34  public function ‪render(): array
35  {
36  $languageService = $this->‪getLanguageService();
37  $result = $this->‪initializeResultArray();
38 
39  $fieldName = $this->data['fieldName'];
40  $fieldId = ‪StringUtility::getUniqueId('formengine-localization-state-selector-');
41  $l10nStateFieldName = 'l10n_state';
42  if (
43  !isset($this->data['defaultLanguageRow'])
44  || !isset($this->data['processedTca']['columns'][$fieldName]['config']['behaviour']['allowLanguageSynchronization'])
45  || !$this->data['processedTca']['columns'][$fieldName]['config']['behaviour']['allowLanguageSynchronization']
46  ) {
47  return $result;
48  }
49 
50  $l10nParentFieldName = $this->data['processedTca']['ctrl']['transOrigPointerField'] ?? null;
51  $l10nSourceFieldName = $this->data['processedTca']['ctrl']['translationSource'] ?? null;
52 
53  $sourceLanguageTitle = '';
54  $fieldValueInParentRow = '';
55  $fieldValueInSourceRow = null;
56  if ($l10nParentFieldName && $this->data['databaseRow'][$l10nParentFieldName] > 0) {
57  if ($l10nSourceFieldName && $this->data['databaseRow'][$l10nSourceFieldName] > 0) {
58  $languageField = $this->data['processedTca']['ctrl']['languageField'] ?? null;
59  if ($languageField
60  && isset($this->data['sourceLanguageRow'][$languageField])
61  && $this->data['sourceLanguageRow'][$languageField] > 0
62  ) {
63  $languageUidOfSourceRow = $this->data['sourceLanguageRow'][$languageField];
64  $sourceLanguageTitle = $this->data['systemLanguageRows'][$languageUidOfSourceRow]['title'] ?? '';
65  $fieldValueInSourceRow = $this->data['sourceLanguageRow'][$fieldName] ?? null;
66  }
67  }
68  $fieldValueInParentRow = (string)$this->data['defaultLanguageRow'][$fieldName];
69  }
70 
71  $localizationState = ‪State::fromJSON(
72  $this->data['tableName'],
73  $this->data['databaseRow'][$l10nStateFieldName] ?? null
74  );
75 
76  $fieldElementName = 'data[' . htmlspecialchars($this->data['tableName']) . ']'
77  . '[' . htmlspecialchars((string)$this->data['databaseRow']['uid']) . ']'
78  . '[' . htmlspecialchars($l10nStateFieldName) . ']'
79  . '[' . htmlspecialchars($this->data['fieldName']) . ']';
80 
81  $html = [];
82  $html[] = '<div class="t3js-l10n-state-container">';
83  $html[] = '<div>';
84  $html[] = '<strong>';
85  $html[] = $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_wizards.xlf:localizationStateSelector.header');
86  $html[] = '</strong>';
87  $html[] = '</div>';
88  $html[] = '<div class="form-check">';
89  $html[] = '<input';
90  $html[] = ' id="' . $fieldId . '-custom"';
91  $html[] = ' type="radio"';
92  $html[] = ' name="' . htmlspecialchars($fieldElementName) . '"';
93  $html[] = ' class="form-check-input t3js-l10n-state-custom"';
94  $html[] = ' value="custom"';
95  $html[] = $localizationState->isCustomState($fieldName) ? ' checked="checked"' : '';
96  $html[] = ' data-original-language-value=""';
97  $html[] = '>';
98  $html[] = '<label';
99  $html[] = ' for="' . $fieldId . '-custom"';
100  $html[] = ' class="form-check-label"';
101  $html[] = '>';
102  $html[] = $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_wizards.xlf:localizationStateSelector.customValue');
103  $html[] = '</label>';
104  $html[] = '</div>';
105  $html[] = '<div class="form-check">';
106  $html[] = '<input';
107  $html[] = ' id="' . $fieldId . '-parent"';
108  $html[] = ' type="radio"';
109  $html[] = ' name="' . htmlspecialchars($fieldElementName) . '"';
110  $html[] = ' class="form-check-input"';
111  $html[] = ' value="parent"';
112  $html[] = $localizationState->isParentState($fieldName) ? ' checked="checked"' : '';
113  $html[] = ' data-original-language-value="' . htmlspecialchars((string)$fieldValueInParentRow) . '"';
114  $html[] = '>';
115  $html[] = '<label';
116  $html[] = ' for="' . $fieldId . '-parent"';
117  $html[] = ' class="form-check-label"';
118  $html[] = '>';
119  $html[] = $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_wizards.xlf:localizationStateSelector.defaultLanguageValue');
120  $html[] = '</label>';
121  $html[] = '</div>';
122  if ($fieldValueInSourceRow !== null) {
123  $html[] = '<div class="form-check">';
124  $html[] = '<input';
125  $html[] = ' id="' . $fieldId . '-source"';
126  $html[] = ' type="radio"';
127  $html[] = ' name="' . htmlspecialchars($fieldElementName) . '"';
128  $html[] = ' class="form-check-input"';
129  $html[] = ' value="source"';
130  $html[] = $localizationState->isSourceState($fieldName) ? ' checked="checked"' : '';
131  $html[] = ' data-original-language-value="' . htmlspecialchars((string)$fieldValueInSourceRow) . '"';
132  $html[] = '>';
133  $html[] = '<label';
134  $html[] = ' for="' . $fieldId . '-source"';
135  $html[] = ' class="form-check-label"';
136  $html[] = '>';
137  $html[] = sprintf($languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_wizards.xlf:localizationStateSelector.sourceLanguageValue'), htmlspecialchars($sourceLanguageTitle));
138  $html[] = '</label>';
139  $html[] = '</div>';
140  }
141  $html[] = '</div>';
142 
143  $result['javaScriptModules'][] = ‪JavaScriptModuleInstruction::create(
144  '@typo3/backend/form-engine/field-wizard/localization-state-selector.js'
145  )->instance($fieldElementName);
146  $result['html'] = implode(LF, $html);
147  return $result;
148  }
149 
151  {
152  return ‪$GLOBALS['LANG'];
153  }
154 }
‪TYPO3\CMS\Backend\Form\FieldWizard\LocalizationStateSelector
Definition: LocalizationStateSelector.php:30
‪TYPO3\CMS\Core\Page\JavaScriptModuleInstruction\create
‪static create(string $name, string $exportName=null)
Definition: JavaScriptModuleInstruction.php:47
‪TYPO3\CMS\Core\Page\JavaScriptModuleInstruction
Definition: JavaScriptModuleInstruction.php:23
‪TYPO3\CMS\Core\DataHandling\Localization\State
Definition: State.php:26
‪TYPO3\CMS\Backend\Form\FieldWizard
Definition: DefaultLanguageDifferences.php:18
‪TYPO3\CMS\Core\DataHandling\Localization\State\fromJSON
‪static fromJSON(string $tableName, string $json=null)
Definition: State.php:43
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Backend\Form\AbstractNode
Definition: AbstractNode.php:29
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:24
‪TYPO3\CMS\Backend\Form\FieldWizard\LocalizationStateSelector\getLanguageService
‪getLanguageService()
Definition: LocalizationStateSelector.php:150
‪TYPO3\CMS\Backend\Form\FieldWizard\LocalizationStateSelector\render
‪render()
Definition: LocalizationStateSelector.php:34
‪TYPO3\CMS\Core\Utility\StringUtility\getUniqueId
‪static getUniqueId(string $prefix='')
Definition: StringUtility.php:57
‪TYPO3\CMS\Backend\Form\AbstractNode\initializeResultArray
‪initializeResultArray()
Definition: AbstractNode.php:77