|
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
|
|
|
|
|
18
|
|
|
namespace TYPO3\CMS\Backend\View\BackendLayout\Grid; |
|
19
|
|
|
|
|
20
|
|
|
use TYPO3\CMS\Backend\Routing\UriBuilder; |
|
21
|
|
|
use TYPO3\CMS\Backend\Utility\BackendUtility; |
|
22
|
|
|
use TYPO3\CMS\Backend\View\PageLayoutContext; |
|
23
|
|
|
use TYPO3\CMS\Core\Type\Bitmask\Permission; |
|
24
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Grid Column |
|
28
|
|
|
* |
|
29
|
|
|
* Object representation (model/proxy) for a single column from a grid defined |
|
30
|
|
|
* in a BackendLayout. Stores GridColumnItem representations of content records |
|
31
|
|
|
* and provides getter methods which return various properties associated with |
|
32
|
|
|
* a single column, e.g. the "edit all elements in content" URL and the "add |
|
33
|
|
|
* new content element" URL of the button that is placed in the top of columns |
|
34
|
|
|
* in the page layout. |
|
35
|
|
|
* |
|
36
|
|
|
* Accessed from Fluid templates. |
|
37
|
|
|
* |
|
38
|
|
|
* @internal this is experimental and subject to change in TYPO3 v10 / v11 |
|
39
|
|
|
*/ |
|
40
|
|
|
class GridColumn extends AbstractGridObject |
|
41
|
|
|
{ |
|
42
|
|
|
/** |
|
43
|
|
|
* @var GridColumnItem[] |
|
44
|
|
|
*/ |
|
45
|
|
|
protected $items = []; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @var int|null |
|
49
|
|
|
*/ |
|
50
|
|
|
protected $columnNumber; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @var string |
|
54
|
|
|
*/ |
|
55
|
|
|
protected $columnName = 'default'; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @var string|null |
|
59
|
|
|
*/ |
|
60
|
|
|
protected $icon; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @var int |
|
64
|
|
|
*/ |
|
65
|
|
|
protected $colSpan = 1; |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @var int |
|
69
|
|
|
*/ |
|
70
|
|
|
protected $rowSpan = 1; |
|
71
|
|
|
|
|
72
|
|
|
public function __construct(PageLayoutContext $context, array $columnDefinition) |
|
73
|
|
|
{ |
|
74
|
|
|
parent::__construct($context); |
|
75
|
|
|
$this->columnNumber = isset($columnDefinition['colPos']) ? (int)$columnDefinition['colPos'] : null; |
|
76
|
|
|
$this->columnName = $columnDefinition['name'] ?? $this->columnName; |
|
77
|
|
|
$this->icon = $columnDefinition['icon'] ?? $this->icon; |
|
78
|
|
|
$this->colSpan = (int)($columnDefinition['colspan'] ?? $this->colSpan); |
|
79
|
|
|
$this->rowSpan = (int)($columnDefinition['rowspan'] ?? $this->rowSpan); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function isActive(): bool |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->columnNumber !== null && in_array($this->columnNumber, $this->context->getDrawingConfiguration()->getActiveColumns()); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function addItem(GridColumnItem $item): void |
|
88
|
|
|
{ |
|
89
|
|
|
$this->items[] = $item; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @return GridColumnItem[] |
|
94
|
|
|
*/ |
|
95
|
|
|
public function getItems(): iterable |
|
96
|
|
|
{ |
|
97
|
|
|
return $this->items; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public function getColumnNumber(): ?int |
|
101
|
|
|
{ |
|
102
|
|
|
return $this->columnNumber; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public function getColumnName(): string |
|
106
|
|
|
{ |
|
107
|
|
|
return $this->columnName; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public function getIcon(): ?string |
|
111
|
|
|
{ |
|
112
|
|
|
return $this->icon; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
public function getColSpan(): int |
|
116
|
|
|
{ |
|
117
|
|
|
if ($this->context->getDrawingConfiguration()->getLanguageMode()) { |
|
118
|
|
|
return 1; |
|
119
|
|
|
} |
|
120
|
|
|
return $this->colSpan; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
public function getRowSpan(): int |
|
124
|
|
|
{ |
|
125
|
|
|
if ($this->context->getDrawingConfiguration()->getLanguageMode()) { |
|
126
|
|
|
return 1; |
|
127
|
|
|
} |
|
128
|
|
|
return $this->rowSpan; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* @return int[] |
|
133
|
|
|
*/ |
|
134
|
|
|
public function getAllContainedItemUids(): array |
|
135
|
|
|
{ |
|
136
|
|
|
$uids = []; |
|
137
|
|
|
foreach ($this->items as $columnItem) { |
|
138
|
|
|
$uids[] = (int)$columnItem->getRecord()['uid']; |
|
139
|
|
|
} |
|
140
|
|
|
return $uids; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
public function getEditUrl(): ?string |
|
144
|
|
|
{ |
|
145
|
|
|
if (empty($this->items)) { |
|
146
|
|
|
return null; |
|
147
|
|
|
} |
|
148
|
|
|
$pageRecord = $this->context->getPageRecord(); |
|
149
|
|
|
if (!$this->getBackendUser()->doesUserHaveAccess($pageRecord, Permission::CONTENT_EDIT) |
|
150
|
|
|
|| !$this->getBackendUser()->checkLanguageAccess($this->context->getSiteLanguage()->getLanguageId())) { |
|
151
|
|
|
return null; |
|
152
|
|
|
} |
|
153
|
|
|
$pageTitleParamForAltDoc = '&recTitle=' . rawurlencode( |
|
154
|
|
|
BackendUtility::getRecordTitle('pages', $pageRecord, true) |
|
155
|
|
|
); |
|
156
|
|
|
$editParam = '&edit[tt_content][' . implode(',', $this->getAllContainedItemUids()) . ']=edit' . $pageTitleParamForAltDoc; |
|
157
|
|
|
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); |
|
158
|
|
|
return $uriBuilder->buildUriFromRoute('record_edit') . $editParam . '&returnUrl=' . rawurlencode($GLOBALS['TYPO3_REQUEST']->getAttribute('normalizedParams')->getRequestUri()); |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
public function getNewContentUrl(): string |
|
162
|
|
|
{ |
|
163
|
|
|
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); |
|
164
|
|
|
$pageId = $this->context->getPageId(); |
|
165
|
|
|
|
|
166
|
|
|
if ($this->context->getDrawingConfiguration()->getShowNewContentWizard()) { |
|
167
|
|
|
$urlParameters = [ |
|
168
|
|
|
'id' => $pageId, |
|
169
|
|
|
'sys_language_uid' => $this->context->getSiteLanguage()->getLanguageId(), |
|
170
|
|
|
'colPos' => $this->getColumnNumber(), |
|
171
|
|
|
'uid_pid' => $pageId, |
|
172
|
|
|
'returnUrl' => $GLOBALS['TYPO3_REQUEST']->getAttribute('normalizedParams')->getRequestUri() |
|
173
|
|
|
]; |
|
174
|
|
|
$routeName = BackendUtility::getPagesTSconfig($pageId)['mod.']['newContentElementWizard.']['override'] |
|
175
|
|
|
?? 'new_content_element_wizard'; |
|
176
|
|
|
} else { |
|
177
|
|
|
$urlParameters = [ |
|
178
|
|
|
'edit' => [ |
|
179
|
|
|
'tt_content' => [ |
|
180
|
|
|
$pageId => 'new' |
|
181
|
|
|
] |
|
182
|
|
|
], |
|
183
|
|
|
'defVals' => [ |
|
184
|
|
|
'tt_content' => [ |
|
185
|
|
|
'colPos' => $this->getColumnNumber(), |
|
186
|
|
|
'sys_language_uid' => $this->context->getSiteLanguage()->getLanguageId() |
|
187
|
|
|
] |
|
188
|
|
|
], |
|
189
|
|
|
'returnUrl' => $GLOBALS['TYPO3_REQUEST']->getAttribute('normalizedParams')->getRequestUri() |
|
190
|
|
|
]; |
|
191
|
|
|
$routeName = 'record_edit'; |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
return (string)$uriBuilder->buildUriFromRoute($routeName, $urlParameters); |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
public function getTitle(): string |
|
198
|
|
|
{ |
|
199
|
|
|
$columnNumber = $this->getColumnNumber(); |
|
200
|
|
|
$colTitle = BackendUtility::getProcessedValue('tt_content', 'colPos', (string)$columnNumber) ?? ''; |
|
201
|
|
|
foreach ($this->context->getBackendLayout()->getUsedColumns() as $colPos => $title) { |
|
202
|
|
|
if ($colPos === $columnNumber) { |
|
203
|
|
|
$colTitle = (string)$this->getLanguageService()->sL($title); |
|
204
|
|
|
} |
|
205
|
|
|
} |
|
206
|
|
|
return $colTitle; |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
public function getTitleInaccessible(): string |
|
210
|
|
|
{ |
|
211
|
|
|
return $this->getLanguageService()->sL($this->columnName) . ' (' . $this->getLanguageService()->getLL('noAccess') . ')'; |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
public function getTitleUnassigned(): string |
|
215
|
|
|
{ |
|
216
|
|
|
return $this->getLanguageService()->sL($this->columnName) . ' (' . $this->getLanguageService()->getLL('notAssigned') . ')'; |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
public function isUnassigned(): bool |
|
220
|
|
|
{ |
|
221
|
|
|
return $this->columnName !== 'unused' && $this->columnNumber === null; |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
public function isUnused(): bool |
|
225
|
|
|
{ |
|
226
|
|
|
return $this->columnName === 'unused' && $this->columnNumber === null; |
|
227
|
|
|
} |
|
228
|
|
|
|
|
229
|
|
|
public function isContentEditable(): bool |
|
230
|
|
|
{ |
|
231
|
|
|
if ($this->columnName === 'unused' || $this->columnNumber === null) { |
|
232
|
|
|
return false; |
|
233
|
|
|
} |
|
234
|
|
|
if ($this->getBackendUser()->isAdmin()) { |
|
235
|
|
|
return true; |
|
236
|
|
|
} |
|
237
|
|
|
$pageRecord = $this->context->getPageRecord(); |
|
238
|
|
|
return !$pageRecord['editlock'] |
|
239
|
|
|
&& $this->getBackendUser()->doesUserHaveAccess($pageRecord, Permission::CONTENT_EDIT) |
|
240
|
|
|
&& $this->getBackendUser()->checkLanguageAccess($this->context->getSiteLanguage()->getLanguageId()); |
|
241
|
|
|
} |
|
242
|
|
|
} |
|
243
|
|
|
|