|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
|
|
4
|
|
|
namespace TYPO3\CMS\Backend\View\BackendLayout\Grid; |
|
5
|
|
|
|
|
6
|
|
|
/* |
|
7
|
|
|
* This file is part of the TYPO3 CMS project. |
|
8
|
|
|
* |
|
9
|
|
|
* It is free software; you can redistribute it and/or modify it under |
|
10
|
|
|
* the terms of the GNU General Public License, either version 2 |
|
11
|
|
|
* of the License, or any later version. |
|
12
|
|
|
* |
|
13
|
|
|
* For the full copyright and license information, please read the |
|
14
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
15
|
|
|
* |
|
16
|
|
|
* The TYPO3 project - inspiring people to share! |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
use TYPO3\CMS\Backend\Routing\UriBuilder; |
|
20
|
|
|
use TYPO3\CMS\Backend\Utility\BackendUtility; |
|
21
|
|
|
use TYPO3\CMS\Backend\View\BackendLayout\BackendLayout; |
|
22
|
|
|
use TYPO3\CMS\Core\Imaging\Icon; |
|
23
|
|
|
use TYPO3\CMS\Core\Site\Entity\SiteLanguage; |
|
24
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
25
|
|
|
use TYPO3\CMS\Core\Versioning\VersionState; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Language Column |
|
29
|
|
|
* |
|
30
|
|
|
* Object representation of a site language selected in the "page" module |
|
31
|
|
|
* to show translations of content elements. |
|
32
|
|
|
* |
|
33
|
|
|
* Contains getter methods to return various values associated with a single |
|
34
|
|
|
* language, e.g. localized page title, associated SiteLanguage instance, |
|
35
|
|
|
* edit URLs and link titles and so on. |
|
36
|
|
|
* |
|
37
|
|
|
* Stores a duplicated Grid object associated with the SiteLanguage. |
|
38
|
|
|
* |
|
39
|
|
|
* Accessed from Fluid templates - generated from within BackendLayout when |
|
40
|
|
|
* "page" module is in "languages" mode. |
|
41
|
|
|
*/ |
|
42
|
|
|
class LanguageColumn extends AbstractGridObject |
|
43
|
|
|
{ |
|
44
|
|
|
/** |
|
45
|
|
|
* @var SiteLanguage |
|
46
|
|
|
*/ |
|
47
|
|
|
protected $siteLanguage; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @var array |
|
51
|
|
|
*/ |
|
52
|
|
|
protected $localizedPageRecord = []; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @var array |
|
56
|
|
|
*/ |
|
57
|
|
|
protected $localizationConfiguration = []; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @var GridColumn|null |
|
61
|
|
|
*/ |
|
62
|
|
|
protected $grid; |
|
63
|
|
|
|
|
64
|
|
|
public function __construct(BackendLayout $backendLayout, SiteLanguage $language) |
|
65
|
|
|
{ |
|
66
|
|
|
parent::__construct($backendLayout); |
|
67
|
|
|
$this->siteLanguage = $language; |
|
68
|
|
|
$this->localizationConfiguration = BackendUtility::getPagesTSconfig($backendLayout->getDrawingConfiguration()->getPageId())['mod.']['web_layout.']['localization.'] ?? []; |
|
69
|
|
|
if ($this->siteLanguage->getLanguageId() > 0) { |
|
70
|
|
|
$pageLocalizationRecord = BackendUtility::getRecordLocalization( |
|
71
|
|
|
'pages', |
|
72
|
|
|
$backendLayout->getDrawingConfiguration()->getPageId(), |
|
73
|
|
|
$language->getLanguageId() |
|
74
|
|
|
); |
|
75
|
|
|
if (is_array($pageLocalizationRecord)) { |
|
76
|
|
|
$pageLocalizationRecord = reset($pageLocalizationRecord); |
|
77
|
|
|
} |
|
78
|
|
|
BackendUtility::workspaceOL('pages', $pageLocalizationRecord); |
|
79
|
|
|
$this->localizedPageRecord = $pageLocalizationRecord; |
|
80
|
|
|
} else { |
|
81
|
|
|
$this->localizedPageRecord = $backendLayout->getDrawingConfiguration()->getPageRecord(); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function getLocalizedPageRecord(): ?array |
|
86
|
|
|
{ |
|
87
|
|
|
return $this->localizedPageRecord ?: null; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function getSiteLanguage(): SiteLanguage |
|
91
|
|
|
{ |
|
92
|
|
|
return $this->siteLanguage; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public function getGrid(): Grid |
|
96
|
|
|
{ |
|
97
|
|
|
if (empty($this->grid)) { |
|
98
|
|
|
$this->grid = $this->backendLayout->getGrid(); |
|
|
|
|
|
|
99
|
|
|
} |
|
100
|
|
|
return $this->grid; |
|
|
|
|
|
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function getLanguageModeLabelClass(): string |
|
104
|
|
|
{ |
|
105
|
|
|
$contentRecordsPerColumn = $this->backendLayout->getContentFetcher()->getFlatContentRecords(); |
|
106
|
|
|
$translationData = $this->backendLayout->getContentFetcher()->getTranslationData($contentRecordsPerColumn, $this->siteLanguage->getLanguageId()); |
|
107
|
|
|
return $translationData['mode'] === 'mixed' ? 'danger' : 'info'; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public function getLanguageMode(): string |
|
111
|
|
|
{ |
|
112
|
|
|
switch ($this->backendLayout->getLanguageModeIdentifier()) { |
|
113
|
|
|
case 'mixed': |
|
114
|
|
|
$languageMode = $this->getLanguageService()->getLL('languageModeMixed'); |
|
115
|
|
|
break; |
|
116
|
|
|
case 'connected': |
|
117
|
|
|
$languageMode = $this->getLanguageService()->getLL('languageModeConnected'); |
|
118
|
|
|
break; |
|
119
|
|
|
case 'free': |
|
120
|
|
|
$languageMode = $this->getLanguageService()->getLL('languageModeFree'); |
|
121
|
|
|
break; |
|
122
|
|
|
default: |
|
123
|
|
|
$languageMode = ''; |
|
124
|
|
|
} |
|
125
|
|
|
return $languageMode; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
public function getPageIcon(): string |
|
129
|
|
|
{ |
|
130
|
|
|
return BackendUtility::wrapClickMenuOnIcon( |
|
131
|
|
|
$this->iconFactory->getIconForRecord('pages', $this->localizedPageRecord, Icon::SIZE_SMALL)->render(), |
|
132
|
|
|
'pages', |
|
133
|
|
|
$this->localizedPageRecord['uid'] |
|
134
|
|
|
); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
public function getAllowTranslate(): bool |
|
138
|
|
|
{ |
|
139
|
|
|
return ($this->localizationConfiguration['enableTranslate'] ?? true) && !($this->getTranslationData()['hasStandAloneContent'] ?? false); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
public function getTranslationData(): array |
|
143
|
|
|
{ |
|
144
|
|
|
$contentFetcher = $this->backendLayout->getContentFetcher(); |
|
145
|
|
|
return $contentFetcher->getTranslationData($contentFetcher->getFlatContentRecords(), $this->siteLanguage->getLanguageId()); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
public function getAllowTranslateCopy(): bool |
|
149
|
|
|
{ |
|
150
|
|
|
return ($this->localizationConfiguration['enableCopy'] ?? true) && !($this->getTranslationData()['hasTranslations'] ?? false); |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
public function getTranslatePageTitle(): string |
|
154
|
|
|
{ |
|
155
|
|
|
return $this->getLanguageService()->getLL('newPageContent_translate'); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
public function getAllowEditPage(): bool |
|
159
|
|
|
{ |
|
160
|
|
|
return $this->getBackendUser()->check('tables_modify', 'pages'); |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
public function getPageEditTitle(): string |
|
164
|
|
|
{ |
|
165
|
|
|
return $this->getLanguageService()->getLL('edit'); |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
public function getPageEditUrl(): string |
|
169
|
|
|
{ |
|
170
|
|
|
$urlParameters = [ |
|
171
|
|
|
'edit' => [ |
|
172
|
|
|
'pages' => [ |
|
173
|
|
|
$this->localizedPageRecord['uid'] => 'edit' |
|
174
|
|
|
] |
|
175
|
|
|
], |
|
176
|
|
|
// Disallow manual adjustment of the language field for pages |
|
177
|
|
|
'overrideVals' => [ |
|
178
|
|
|
'pages' => [ |
|
179
|
|
|
'sys_language_uid' => $this->siteLanguage->getLanguageId() |
|
180
|
|
|
] |
|
181
|
|
|
], |
|
182
|
|
|
'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI') |
|
183
|
|
|
]; |
|
184
|
|
|
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); |
|
185
|
|
|
return (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters); |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
public function getAllowViewPage(): bool |
|
189
|
|
|
{ |
|
190
|
|
|
return !VersionState::cast($this->backendLayout->getDrawingConfiguration()->getPageRecord()['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER); |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
public function getViewPageLinkTitle(): string |
|
194
|
|
|
{ |
|
195
|
|
|
return $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.showPage'); |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
public function getViewPageOnClick(): string |
|
199
|
|
|
{ |
|
200
|
|
|
$pageId = $this->backendLayout->getDrawingConfiguration()->getPageId(); |
|
201
|
|
|
return BackendUtility::viewOnClick( |
|
202
|
|
|
$pageId, |
|
203
|
|
|
'', |
|
204
|
|
|
BackendUtility::BEgetRootLine($pageId), |
|
205
|
|
|
'', |
|
206
|
|
|
'', |
|
207
|
|
|
'&L=' . $this->backendLayout->getDrawingConfiguration()->getLanguageColumnsPointer() |
|
208
|
|
|
); |
|
209
|
|
|
} |
|
210
|
|
|
} |
|
211
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..