TYPO3 CMS  TYPO3_8-7
PageProvider.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 
19 
24 {
28  protected $table = 'pages';
29 
33  protected $itemsConfiguration = [
34  'view' => [
35  'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.view',
36  'iconIdentifier' => 'actions-document-view',
37  'callbackAction' => 'viewRecord'
38  ],
39  'edit' => [
40  'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.edit',
41  'iconIdentifier' => 'actions-page-open',
42  'callbackAction' => 'editRecord'
43  ],
44  'new' => [
45  'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.new',
46  'iconIdentifier' => 'actions-document-new',
47  'callbackAction' => 'newRecord'
48  ],
49  'info' => [
50  'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.info',
51  'iconIdentifier' => 'actions-document-info',
52  'callbackAction' => 'openInfoPopUp'
53  ],
54  'divider1' => [
55  'type' => 'divider'
56  ],
57  'copy' => [
58  'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.copy',
59  'iconIdentifier' => 'actions-edit-copy',
60  'callbackAction' => 'copy'
61  ],
62  'copyRelease' => [
63  'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.copy',
64  'iconIdentifier' => 'actions-edit-copy-release',
65  'callbackAction' => 'clipboardRelease'
66  ],
67  'cut' => [
68  'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.cut',
69  'iconIdentifier' => 'actions-edit-cut',
70  'callbackAction' => 'cut'
71  ],
72  'cutRelease' => [
73  'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.cutrelease',
74  'iconIdentifier' => 'actions-edit-cut-release',
75  'callbackAction' => 'clipboardRelease'
76  ],
77  'pasteAfter' => [
78  'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.pasteafter',
79  'iconIdentifier' => 'actions-document-paste-after',
80  'callbackAction' => 'pasteAfter'
81  ],
82  'pasteInto' => [
83  'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.pasteinto',
84  'iconIdentifier' => 'actions-document-paste-into',
85  'callbackAction' => 'pasteInto'
86  ],
87  'divider2' => [
88  'type' => 'divider'
89  ],
90  'more' => [
91  'type' => 'submenu',
92  'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.more',
93  'iconIdentifier' => '',
94  'callbackAction' => 'openSubmenu',
95  'childItems' => [
96  'newWizard' => [
97  'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_misc.xlf:CM_newWizard',
98  'iconIdentifier' => 'actions-page-new',
99  'callbackAction' => 'newPageWizard',
100  ],
101  'openListModule' => [
102  'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_misc.xlf:CM_db_list',
103  'iconIdentifier' => 'actions-system-list-open',
104  'callbackAction' => 'openListModule',
105  ],
106  'mountAsTreeRoot' => [
107  'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.tempMountPoint',
108  'iconIdentifier' => 'actions-pagetree-mountroot',
109  'callbackAction' => 'mountAsTreeRoot',
110  ],
111  ],
112  ],
113  'divider3' => [
114  'type' => 'divider'
115  ],
116  'enable' => [
117  'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:enable',
118  'iconIdentifier' => 'actions-edit-unhide',
119  'callbackAction' => 'enableRecord',
120  ],
121  'disable' => [
122  'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:disable',
123  'iconIdentifier' => 'actions-edit-hide',
124  'callbackAction' => 'disableRecord',
125  ],
126  'delete' => [
127  'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.delete',
128  'iconIdentifier' => 'actions-edit-delete',
129  'callbackAction' => 'deleteRecord',
130  ],
131  'history' => [
132  'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_misc.xlf:CM_history',
133  'iconIdentifier' => 'actions-document-history-open',
134  'callbackAction' => 'openHistoryPopUp',
135  ],
136  'clearCache' => [
137  'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.clear_cache',
138  'iconIdentifier' => 'actions-system-cache-clear',
139  'callbackAction' => 'clearCache',
140  ],
141  ];
142 
148  public function canHandle(): bool
149  {
150  return $this->table === 'pages';
151  }
152 
156  public function getPriority(): int
157  {
158  return 100;
159  }
160 
166  protected function canRender(string $itemName, string $type): bool
167  {
168  if (in_array($type, ['divider', 'submenu'], true)) {
169  return true;
170  }
171  if (in_array($itemName, $this->disabledItems, true)) {
172  return false;
173  }
174  $canRender = false;
175  switch ($itemName) {
176  case 'view':
177  $canRender = $this->canBeViewed();
178  break;
179  case 'edit':
180  $canRender = $this->canBeEdited();
181  break;
182  case 'new':
183  case 'newWizard':
184  $canRender = $this->canBeCreated();
185  break;
186  case 'info':
187  $canRender = $this->canShowInfo();
188  break;
189  case 'enable':
190  $canRender = $this->canBeEnabled();
191  break;
192  case 'disable':
193  $canRender = $this->canBeDisabled();
194  break;
195  case 'delete':
196  $canRender = $this->canBeDeleted();
197  break;
198  case 'history':
199  $canRender = $this->canShowHistory();
200  break;
201  case 'openListModule':
202  $canRender = $this->canOpenListModule();
203  break;
204  case 'mountAsTreeRoot':
205  $canRender = !$this->isRoot();
206  break;
207  case 'copy':
208  $canRender = $this->canBeCopied();
209  break;
210  case 'copyRelease':
211  $canRender = $this->isRecordInClipboard('copy');
212  break;
213  case 'cut':
214  $canRender = $this->canBeCut() && !$this->isRecordInClipboard('cut');
215  break;
216  case 'cutRelease':
217  $canRender = $this->isRecordInClipboard('cut');
218  break;
219  case 'pasteAfter':
220  $canRender = $this->canBePastedAfter();
221  break;
222  case 'pasteInto':
223  $canRender = $this->canBePastedInto();
224  break;
225  case 'clearCache':
226  $canRender = $this->canClearCache();
227  break;
228  }
229  return $canRender;
230  }
231 
235  protected function initPermissions()
236  {
237  $this->pagePermissions = $this->backendUser->calcPerms($this->record);
238  }
239 
245  protected function canBeCreated(): bool
246  {
248  }
249 
255  protected function canBeEdited(): bool
256  {
257  if ($this->isRoot()) {
258  return false;
259  }
260  if (isset($GLOBALS['TCA'][$this->table]['ctrl']['readOnly']) && $GLOBALS['TCA'][$this->table]['ctrl']['readOnly']) {
261  return false;
262  }
263  if ($this->backendUser->isAdmin()) {
264  return true;
265  }
266  if (isset($GLOBALS['TCA'][$this->table]['ctrl']['adminOnly']) && $GLOBALS['TCA'][$this->table]['ctrl']['adminOnly']) {
267  return false;
268  }
269  return !$this->isRecordLocked() && $this->hasPagePermission(Permission::PAGE_EDIT);
270  }
271 
277  protected function isRecordLocked(): bool
278  {
279  return (bool)$this->record['editlock'];
280  }
281 
287  protected function canBeCut(): bool
288  {
289  return !$this->isWebMount()
290  && $this->canBeEdited()
291  && !$this->isDeletePlaceholder();
292  }
293 
299  protected function canBeCopied(): bool
300  {
301  return !$this->isRoot()
302  && !$this->isWebMount()
303  && !$this->isRecordInClipboard('copy')
305  && !$this->isDeletePlaceholder();
306  }
307 
313  protected function canBePastedInto(): bool
314  {
315  $clipboardElementCount = count($this->clipboard->elFromTable($this->table));
316 
317  return $clipboardElementCount
318  && $this->canBeCreated()
319  && !$this->isDeletePlaceholder();
320  }
321 
327  protected function canBePastedAfter(): bool
328  {
329  $clipboardElementCount = count($this->clipboard->elFromTable($this->table));
330  return $clipboardElementCount
331  && $this->canBeCreated()
332  && !$this->isDeletePlaceholder();
333  }
334 
340  protected function canBeDeleted(): bool
341  {
342  return !$this->isDeletePlaceholder()
343  && !$this->isRecordLocked()
344  && !$this->isDeletionDisabledInTS()
346  }
347 
353  protected function canBeViewed(): bool
354  {
355  return !$this->isRoot() && !$this->isDeleted();
356  }
357 
363  protected function canShowInfo(): bool
364  {
365  return !$this->isRoot();
366  }
367 
373  protected function canClearCache(): bool
374  {
375  return !$this->isRoot()
376  && ($this->backendUser->isAdmin() || $this->backendUser->getTSConfigVal('options.clearCache.pages'));
377  }
378 
384  protected function isDeleted(): bool
385  {
386  return !empty($this->record['deleted']) || $this->isDeletePlaceholder();
387  }
388 
394  protected function isRoot()
395  {
396  return (int)$this->identifier === 0;
397  }
398 
404  protected function isWebMount()
405  {
406  return in_array($this->identifier, $this->backendUser->returnWebmounts());
407  }
408 
413  protected function getAdditionalAttributes(string $itemName): array
414  {
415  $attributes = [];
416  if ($itemName === 'view') {
417  $attributes += $this->getViewAdditionalAttributes();
418  }
419  if ($itemName === 'delete') {
420  $attributes += $this->getDeleteAdditionalAttributes();
421  }
422  if ($itemName === 'pasteInto') {
423  $attributes += $this->getPasteAdditionalAttributes('into');
424  }
425  if ($itemName === 'pasteAfter') {
426  $attributes += $this->getPasteAdditionalAttributes('after');
427  }
428  return $attributes;
429  }
430 
434  protected function getPreviewPid(): int
435  {
436  return (int)$this->record['uid'];
437  }
438 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']