TYPO3 CMS  TYPO3_8-7
LocalizationStateSelector.php
Go to the documentation of this file.
1 <?php
2 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 
21 
26 {
32  public function render(): array
33  {
34  $languageService = $this->getLanguageService();
35  $result = $this->initializeResultArray();
36 
37  $fieldName = $this->data['fieldName'];
38  $l10nStateFieldName = '';
39  if (isset($l10nStateFieldName)) {
40  $l10nStateFieldName = 'l10n_state';
41  }
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:lang/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:lang/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:lang/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:lang/Resources/Private/Language/locallang_wizards.xlf:localizationStateSelector.sourceLanguageValue'), htmlspecialchars($sourceLanguageTitle));
125  $html[] = '</label>';
126  $html[] = '</div>';
127  }
128  $html[] = '</div>';
129 
130  $result['html'] = implode(LF, $html);
131  return $result;
132  }
133 
137  protected function getLanguageService()
138  {
139  return $GLOBALS['LANG'];
140  }
141 }
static fromJSON(string $tableName, string $json=null)
Definition: State.php:49
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']