‪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  $queryString .= http_build_query($event->‪getAdditionalQueryParameters(), '', '&', PHP_QUERY_RFC3986);
53  }
54  // Reassemble encapsulated language id as query parameter, to open workspace preview in correct non-default language
55  if ($event->‪getLanguageId() > 0) {
56  $queryString .= '&_language=' . $event->‪getLanguageId();
57  }
58  if ($queryString) {
59  $uri = $uri->withQuery($queryString);
60  }
61  $event->‪setPreviewUri($uri);
62  }
63 
67  #[AsEventListener('typo3-workspaces/display-editing-staged-element-information')]
69  {
70  $tableName = $event->‪getTableName();
71  if ($this->‪getBackendUser()->workspace === 0 || !BackendUtility::isTableWorkspaceEnabled($tableName)) {
72  return;
73  }
74 
75  ‪$record = BackendUtility::getRecordWSOL($tableName, (int)($event->‪getDatabaseRow()['uid'] ?? 0));
76  if (!isset(‪$record['t3ver_stage']) || abs(‪$record['t3ver_stage']) <= ‪StagesService::STAGE_EDIT_ID) {
77  return;
78  }
79 
80  $stages = GeneralUtility::makeInstance(StagesService::class);
81  $stageName = $stages->getStageTitle((int)‪$record['t3ver_stage']);
82  $editingName = $stages->getStageTitle(‪StagesService::STAGE_EDIT_ID);
83  $message = ($languageService = $this->‪getLanguageService()) !== null
84  ? $languageService->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:info.elementAlreadyModified')
85  : 'Element is in workspace stage "%s", modifications will send it back to "%s".';
86 
87  GeneralUtility::makeInstance(FlashMessageService::class)
88  ->getMessageQueueByIdentifier()
89  ->enqueue(
90  GeneralUtility::makeInstance(FlashMessage::class, sprintf($message, $stageName, $editingName), '', ContextualFeedbackSeverity::INFO, true)
91  );
92  }
93 
95  {
96  return ‪$GLOBALS['LANG'] ?? null;
97  }
98 
100  {
101  return ‪$GLOBALS['BE_USER'];
102  }
103 }
‪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:99
‪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:94
‪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:68
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:61
‪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