‪TYPO3CMS  ‪main
PageTreeItemsHighlighter.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 
28 
35 {
36  public function ‪__construct(
37  private readonly ‪WorkspaceService $workspaceService
38  ) {}
39 
40  #[AsEventListener('typo3-workspaces/page-tree-items-highlighter')]
41  public function ‪__invoke(‪AfterPageTreeItemsPreparedEvent $event): void
42  {
43  $items = $event->‪getItems();
44  $workspaceId = $this->‪getBackendUser()->workspace;
45 
46  if ($workspaceId <= 0 || $items === []) {
47  return;
48  }
49 
50  foreach ($items as &$item) {
51  $page = $item['_page'] ?? [];
52  if (!is_array($page) || $page === []) {
53  continue;
54  }
55 
56  if ((int)($page['t3ver_wsid'] ?? 0) === $workspaceId
57  && (
58  (int)($page['t3ver_oid'] ?? 0) > 0
59  || VersionState::tryFrom($page['t3ver_state'] ?? 0) === VersionState::NEW_PLACEHOLDER
60  )
61  ) {
62  $label = $this->‪getLanguageService()->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:status.has_changes');
63  if (VersionState::tryFrom($page['t3ver_state'] ?? 0) === VersionState::NEW_PLACEHOLDER) {
64  $label = $this->‪getLanguageService()->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:status.is_new');
65  }
66  $item['statusInformation'][] = new ‪StatusInformation(
67  label: $label,
68  severity: ContextualFeedbackSeverity::WARNING,
69  );
70  } elseif (
71  $this->workspaceService->hasPageRecordVersions(
72  $workspaceId,
73  (int)(($page['t3ver_oid'] ?? 0) ?: ($page['uid'] ?? 0))
74  )
75  ) {
76  $item['statusInformation'][] = new ‪StatusInformation(
77  label: $this->‪getLanguageService()->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:status.contains_changes'),
78  severity: ContextualFeedbackSeverity::WARNING,
79  );
80  }
81  }
82  unset($item);
83 
84  $event->‪setItems($items);
85  }
86 
88  {
89  return ‪$GLOBALS['LANG'];
90  }
91 
93  {
94  return ‪$GLOBALS['BE_USER'];
95  }
96 }
‪TYPO3\CMS\Backend\Controller\Event\AfterPageTreeItemsPreparedEvent
Definition: AfterPageTreeItemsPreparedEvent.php:26
‪TYPO3\CMS\Core\Attribute\AsEventListener
Definition: AsEventListener.php:25
‪TYPO3\CMS\Core\Versioning\VersionState
‪VersionState
Definition: VersionState.php:22
‪TYPO3\CMS\Workspaces\EventListener\PageTreeItemsHighlighter
Definition: PageTreeItemsHighlighter.php:35
‪TYPO3\CMS\Backend\Controller\Event\AfterPageTreeItemsPreparedEvent\setItems
‪setItems(array $items)
Definition: AfterPageTreeItemsPreparedEvent.php:45
‪TYPO3\CMS\Workspaces\EventListener\PageTreeItemsHighlighter\__invoke
‪__invoke(AfterPageTreeItemsPreparedEvent $event)
Definition: PageTreeItemsHighlighter.php:41
‪TYPO3\CMS\Backend\Controller\Event\AfterPageTreeItemsPreparedEvent\getItems
‪getItems()
Definition: AfterPageTreeItemsPreparedEvent.php:40
‪TYPO3\CMS\Core\Type\ContextualFeedbackSeverity
‪ContextualFeedbackSeverity
Definition: ContextualFeedbackSeverity.php:25
‪TYPO3\CMS\Backend\Dto\Tree\Status\StatusInformation
Definition: StatusInformation.php:23
‪TYPO3\CMS\Workspaces\EventListener
Definition: PageTreeItemsHighlighter.php:18
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Workspaces\Service\WorkspaceService
Definition: WorkspaceService.php:38
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Workspaces\EventListener\PageTreeItemsHighlighter\getLanguageService
‪getLanguageService()
Definition: PageTreeItemsHighlighter.php:87
‪TYPO3\CMS\Workspaces\EventListener\PageTreeItemsHighlighter\getBackendUser
‪getBackendUser()
Definition: PageTreeItemsHighlighter.php:92
‪TYPO3\CMS\Workspaces\EventListener\PageTreeItemsHighlighter\__construct
‪__construct(private readonly WorkspaceService $workspaceService)
Definition: PageTreeItemsHighlighter.php:36