‪TYPO3CMS  ‪main
BackendUtilityHook.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 
22 use TYPO3\CMS\Backend\Utility\BackendUtility;
32 
37 {
42  #[AsEventListener('typo3-workspaces/link-modifier')]
44  {
45  if ($this->‪getBackendUser()->workspace === 0) {
46  return;
47  }
48  $uri = GeneralUtility::makeInstance(PreviewUriBuilder::class)
49  ->buildUriForWorkspaceSplitPreview($event->‪getPageId());
50  $queryString = $uri->getQuery();
51  if ($event->‪getAdditionalQueryParameters() !== []) {
52  if ($queryString !== '') {
53  $queryString .= '&';
54  }
55  $queryString .= http_build_query($event->‪getAdditionalQueryParameters(), '', '&', PHP_QUERY_RFC3986);
56  }
57  // Reassemble encapsulated language id as query parameter, to open workspace preview in correct non-default language
58  if ($event->‪getLanguageId() > 0) {
59  $queryString .= '&_language=' . $event->‪getLanguageId();
60  }
61  if ($queryString) {
62  $uri = $uri->withQuery($queryString);
63  }
64  $event->‪setPreviewUri($uri);
65  }
66 
70  #[AsEventListener('typo3-workspaces/display-editing-staged-element-information')]
72  {
73  $tableName = $event->‪getTableName();
74  if ($this->‪getBackendUser()->workspace === 0 || !BackendUtility::isTableWorkspaceEnabled($tableName)) {
75  return;
76  }
77 
78  ‪$record = BackendUtility::getRecordWSOL($tableName, (int)($event->‪getDatabaseRow()['uid'] ?? 0));
79  if (!isset(‪$record['t3ver_stage']) || abs(‪$record['t3ver_stage']) <= ‪StagesService::STAGE_EDIT_ID) {
80  return;
81  }
82 
83  $stages = GeneralUtility::makeInstance(StagesService::class);
84  $stageName = $stages->getStageTitle((int)‪$record['t3ver_stage']);
85  $editingName = $stages->getStageTitle(‪StagesService::STAGE_EDIT_ID);
86  $message = ($languageService = $this->‪getLanguageService()) !== null
87  ? $languageService->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:info.elementAlreadyModified')
88  : 'Element is in workspace stage "%s", modifications will send it back to "%s".';
89 
90  GeneralUtility::makeInstance(FlashMessageService::class)
91  ->getMessageQueueByIdentifier()
92  ->enqueue(
93  GeneralUtility::makeInstance(FlashMessage::class, sprintf($message, $stageName, $editingName), '', ContextualFeedbackSeverity::INFO, true)
94  );
95  }
96 
98  {
99  return ‪$GLOBALS['LANG'] ?? null;
100  }
101 
103  {
104  return ‪$GLOBALS['BE_USER'];
105  }
106 }
‪TYPO3\CMS\Core\Attribute\AsEventListener
Definition: AsEventListener.php:25
‪TYPO3\CMS\Backend\Form\Event\ModifyEditFormUserAccessEvent\getDatabaseRow
‪getDatabaseRow()
Definition: ModifyEditFormUserAccessEvent.php:95
‪TYPO3\CMS\Workspaces\Hook\BackendUtilityHook\getBackendUser
‪getBackendUser()
Definition: BackendUtilityHook.php:102
‪TYPO3\CMS\Backend\Routing\Event\BeforePagePreviewUriGeneratedEvent\getAdditionalQueryParameters
‪getAdditionalQueryParameters()
Definition: BeforePagePreviewUriGeneratedEvent.php:97
‪TYPO3\CMS\Backend\Form\Event\ModifyEditFormUserAccessEvent\getTableName
‪getTableName()
Definition: ModifyEditFormUserAccessEvent.php:78
‪TYPO3\CMS\Workspaces\Hook\BackendUtilityHook\createPageUriForWorkspaceVersion
‪createPageUriForWorkspaceVersion(BeforePagePreviewUriGeneratedEvent $event)
Definition: BackendUtilityHook.php:43
‪TYPO3\CMS\Core\Type\ContextualFeedbackSeverity
‪ContextualFeedbackSeverity
Definition: ContextualFeedbackSeverity.php:25
‪TYPO3\CMS\Workspaces\Hook\BackendUtilityHook\getLanguageService
‪getLanguageService()
Definition: BackendUtilityHook.php:97
‪TYPO3\CMS\Backend\Routing\Event\BeforePagePreviewUriGeneratedEvent\getPageId
‪getPageId()
Definition: BeforePagePreviewUriGeneratedEvent.php:57
‪TYPO3\CMS\Backend\Form\Event\ModifyEditFormUserAccessEvent
Definition: ModifyEditFormUserAccessEvent.php:27
‪TYPO3\CMS\Workspaces\Preview\PreviewUriBuilder
Definition: PreviewUriBuilder.php:47
‪TYPO3\CMS\Webhooks\Message\$record
‪identifier readonly int readonly array $record
Definition: PageModificationMessage.php:36
‪TYPO3\CMS\Workspaces\Hook\BackendUtilityHook\displayEditingStagedElementInformation
‪displayEditingStagedElementInformation(ModifyEditFormUserAccessEvent $event)
Definition: BackendUtilityHook.php:71
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Backend\Routing\Event\BeforePagePreviewUriGeneratedEvent\setPreviewUri
‪setPreviewUri(UriInterface $uri)
Definition: BeforePagePreviewUriGeneratedEvent.php:42
‪TYPO3\CMS\Workspaces\Service\StagesService\STAGE_EDIT_ID
‪const STAGE_EDIT_ID
Definition: StagesService.php:39
‪TYPO3\CMS\Workspaces\Service\StagesService
Definition: StagesService.php:33
‪TYPO3\CMS\Backend\Routing\Event\BeforePagePreviewUriGeneratedEvent
Definition: BeforePagePreviewUriGeneratedEvent.php:29
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:27
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Backend\Routing\Event\BeforePagePreviewUriGeneratedEvent\getLanguageId
‪getLanguageId()
Definition: BeforePagePreviewUriGeneratedEvent.php:67
‪TYPO3\CMS\Core\Messaging\FlashMessageService
Definition: FlashMessageService.php:27
‪TYPO3\CMS\Workspaces\Hook\BackendUtilityHook
Definition: BackendUtilityHook.php:37
‪TYPO3\CMS\Workspaces\Hook
Definition: BackendUtilityHook.php:18