‪TYPO3CMS  10.4
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 
24 
29 {
35  public function ‪render(): array
36  {
37  $languageService = $this->‪getLanguageService();
38  $result = $this->‪initializeResultArray();
39 
40  $fieldName = $this->data['fieldName'];
41  $l10nStateFieldName = 'l10n_state';
42  if (
43  !$l10nStateFieldName
44  || !isset($this->data['defaultLanguageRow'])
45  || !isset($this->data['processedTca']['columns'][$fieldName]['config']['behaviour']['allowLanguageSynchronization'])
46  || !$this->data['processedTca']['columns'][$fieldName]['config']['behaviour']['allowLanguageSynchronization']
47  ) {
48  return $result;
49  }
50 
51  $l10nParentFieldName = $this->data['processedTca']['ctrl']['transOrigPointerField'] ?? null;
52  $l10nSourceFieldName = $this->data['processedTca']['ctrl']['translationSource'] ?? null;
53 
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;
60  if ($languageField
61  && isset($this->data['sourceLanguageRow'][$languageField])
62  && $this->data['sourceLanguageRow'][$languageField] > 0
63  ) {
64  $languageUidOfSourceRow = $this->data['sourceLanguageRow'][$languageField];
65  $sourceLanguageTitle = $this->data['systemLanguageRows'][$languageUidOfSourceRow]['title'] ?? '';
66  $fieldValueInSourceRow = $this->data['sourceLanguageRow'][$fieldName] ?? null;
67  }
68  }
69  $fieldValueInParentRow = (string)$this->data['defaultLanguageRow'][$fieldName];
70  }
71 
72  $localizationState = ‪State::fromJSON(
73  $this->data['tableName'],
74  $this->data['databaseRow'][$l10nStateFieldName] ?? null
75  );
76 
77  $fieldElementName = 'data[' . htmlspecialchars($this->data['tableName']) . ']'
78  . '[' . htmlspecialchars((string)$this->data['databaseRow']['uid']) . ']'
79  . '[' . htmlspecialchars($l10nStateFieldName) . ']'
80  . '[' . htmlspecialchars($this->data['fieldName']) . ']';
81 
82  $html = [];
83  $html[] = '<div class="t3js-l10n-state-container">';
84  $html[] = '<div>';
85  $html[] = '<strong>';
86  $html[] = $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_wizards.xlf:localizationStateSelector.header');
87  $html[] = '</strong>';
88  $html[] = '</div>';
89  $html[] = '<div class="radio radio-inline">';
90  $html[] = '<label>';
91  $html[] = '<input';
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=""';
98  $html[] = '>';
99  $html[] = $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_wizards.xlf:localizationStateSelector.customValue');
100  $html[] = '</label>';
101  $html[] = '</div>';
102  $html[] = '<div class="radio radio-inline">';
103  $html[] = '<label>';
104  $html[] = '<input';
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) . '"';
110  $html[] = '>';
111  $html[] = $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_wizards.xlf:localizationStateSelector.defaultLanguageValue');
112  $html[] = '</label>';
113  $html[] = '</div>';
114  if ($fieldValueInSourceRow !== null) {
115  $html[] = '<div class="radio radio-inline">';
116  $html[] = '<label>';
117  $html[] = '<input';
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) . '"';
123  $html[] = '>';
124  $html[] = sprintf($languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_wizards.xlf:localizationStateSelector.sourceLanguageValue'), htmlspecialchars($sourceLanguageTitle));
125  $html[] = '</label>';
126  $html[] = '</div>';
127  }
128  $html[] = '</div>';
129 
130  $result['requireJsModules'][] = ['TYPO3/CMS/Backend/FormEngine/FieldWizard/LocalizationStateSelector' => '
131  function(LocalizationStateSelector) {
132  new LocalizationStateSelector(' . GeneralUtility::quoteJSvalue($fieldElementName) . ');
133  }'
134  ];
135  $result['html'] = implode(LF, $html);
136  return $result;
137  }
138 
142  protected function ‪getLanguageService()
143  {
144  return ‪$GLOBALS['LANG'];
145  }
146 }
‪TYPO3\CMS\Backend\Form\FieldWizard\LocalizationStateSelector
Definition: LocalizationStateSelector.php:29
‪TYPO3\CMS\Backend\Form\AbstractNode\initializeResultArray
‪array initializeResultArray()
Definition: AbstractNode.php:90
‪TYPO3\CMS\Core\DataHandling\Localization\State
Definition: State.php:24
‪TYPO3\CMS\Backend\Form\FieldWizard
Definition: DefaultLanguageDifferences.php:18
‪TYPO3\CMS\Core\DataHandling\Localization\State\fromJSON
‪static State null fromJSON(string $tableName, string $json=null)
Definition: State.php:50
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Backend\Form\FieldWizard\LocalizationStateSelector\render
‪array render()
Definition: LocalizationStateSelector.php:35
‪TYPO3\CMS\Backend\Form\AbstractNode
Definition: AbstractNode.php:29
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Backend\Form\FieldWizard\LocalizationStateSelector\getLanguageService
‪LanguageService getLanguageService()
Definition: LocalizationStateSelector.php:142