‪TYPO3CMS  ‪main
WorkspaceSelectorToolbarItem.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use Psr\Http\Message\ServerRequestInterface;
26 
33 {
34  private ServerRequestInterface ‪$request;
35  protected array ‪$availableWorkspaces;
36 
37  public function ‪__construct(
38  private readonly ‪WorkspaceService $workspaceService,
39  private readonly ‪UriBuilder $uriBuilder,
40  private readonly ‪BackendViewFactory $backendViewFactory,
41  private readonly ‪ModuleProvider $moduleProvider,
42  ) {
43  $this->availableWorkspaces = $workspaceService->getAvailableWorkspaces();
44  }
45 
46  public function ‪setRequest(ServerRequestInterface ‪$request): void
47  {
48  $this->request = ‪$request;
49  }
50 
54  public function ‪checkAccess(): bool
55  {
56  return count($this->availableWorkspaces) > 1;
57  }
58 
62  public function ‪getItem(): string
63  {
64  if (empty($this->availableWorkspaces)) {
65  return '';
66  }
67  $currentWorkspace = $this->‪getBackendUser()->workspace;
68  $view = $this->backendViewFactory->create($this->request, ['typo3/cms-workspaces']);
69  $view->assign('workspaceTitle', $currentWorkspace > 0 ? $this->workspaceService->getWorkspaceTitle($currentWorkspace) : '');
70  return $view->render('ToolbarItems/ToolbarItem');
71  }
72 
76  public function ‪getDropDown(): string
77  {
78  $topItem = null;
79  $additionalItems = [];
80  $backendUser = $this->‪getBackendUser();
81  $view = $this->backendViewFactory->create($this->request, ['typo3/cms-workspaces']);
82  $activeWorkspace = $backendUser->workspace;
83  foreach ($this->availableWorkspaces as $workspaceId => $label) {
84  $workspaceId = (int)$workspaceId;
85  $item = [
86  'isActive' => $workspaceId === $activeWorkspace,
87  'label' => $label,
88  'link' => (string)$this->uriBuilder->buildUriFromRoute('main', ['changeWorkspace' => $workspaceId]),
89  'workspaceId' => $workspaceId,
90  ];
91  if ($topItem === null) {
92  $topItem = $item;
93  } else {
94  $additionalItems[] = $item;
95  }
96  }
97  // Add the "Go to workspace module" link if there is at least one icon on top and if the access rights are there
98  if ($topItem !== null && $this->moduleProvider->accessGranted('workspaces_admin', $backendUser)) {
99  $view->assign('showLinkToModule', true);
100  }
101  $view->assign('topItem', $topItem);
102  $view->assign('additionalItems', $additionalItems);
103  return $view->render('ToolbarItems/DropDown');
104  }
105 
109  public function ‪getAdditionalAttributes(): array
110  {
111  return [];
112  }
113 
117  public function ‪hasDropDown(): bool
118  {
119  return !empty($this->availableWorkspaces);
120  }
121 
125  public function ‪getIndex(): int
126  {
127  return 40;
128  }
129 
131  {
132  return ‪$GLOBALS['BE_USER'];
133  }
134 }
‪TYPO3\CMS\Workspaces\Backend\ToolbarItems
Definition: WorkspaceSelectorToolbarItem.php:16
‪TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface
Definition: ToolbarItemInterface.php:22
‪TYPO3\CMS\Workspaces\Backend\ToolbarItems\WorkspaceSelectorToolbarItem\__construct
‪__construct(private readonly WorkspaceService $workspaceService, private readonly UriBuilder $uriBuilder, private readonly BackendViewFactory $backendViewFactory, private readonly ModuleProvider $moduleProvider,)
Definition: WorkspaceSelectorToolbarItem.php:37
‪TYPO3\CMS\Backend\View\BackendViewFactory
Definition: BackendViewFactory.php:35
‪TYPO3\CMS\Workspaces\Backend\ToolbarItems\WorkspaceSelectorToolbarItem
Definition: WorkspaceSelectorToolbarItem.php:33
‪TYPO3\CMS\Workspaces\Backend\ToolbarItems\WorkspaceSelectorToolbarItem\checkAccess
‪checkAccess()
Definition: WorkspaceSelectorToolbarItem.php:54
‪TYPO3\CMS\Backend\Module\ModuleProvider
Definition: ModuleProvider.php:29
‪TYPO3\CMS\Workspaces\Backend\ToolbarItems\WorkspaceSelectorToolbarItem\$availableWorkspaces
‪array $availableWorkspaces
Definition: WorkspaceSelectorToolbarItem.php:35
‪TYPO3\CMS\Workspaces\Backend\ToolbarItems\WorkspaceSelectorToolbarItem\$request
‪ServerRequestInterface $request
Definition: WorkspaceSelectorToolbarItem.php:34
‪TYPO3\CMS\Workspaces\Backend\ToolbarItems\WorkspaceSelectorToolbarItem\hasDropDown
‪hasDropDown()
Definition: WorkspaceSelectorToolbarItem.php:117
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:44
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Workspaces\Backend\ToolbarItems\WorkspaceSelectorToolbarItem\getDropDown
‪getDropDown()
Definition: WorkspaceSelectorToolbarItem.php:76
‪TYPO3\CMS\Workspaces\Service\WorkspaceService
Definition: WorkspaceService.php:38
‪TYPO3\CMS\Workspaces\Backend\ToolbarItems\WorkspaceSelectorToolbarItem\getBackendUser
‪getBackendUser()
Definition: WorkspaceSelectorToolbarItem.php:130
‪TYPO3\CMS\Backend\Toolbar\RequestAwareToolbarItemInterface
Definition: RequestAwareToolbarItemInterface.php:27
‪TYPO3\CMS\Workspaces\Backend\ToolbarItems\WorkspaceSelectorToolbarItem\setRequest
‪setRequest(ServerRequestInterface $request)
Definition: WorkspaceSelectorToolbarItem.php:46
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Workspaces\Backend\ToolbarItems\WorkspaceSelectorToolbarItem\getItem
‪getItem()
Definition: WorkspaceSelectorToolbarItem.php:62
‪TYPO3\CMS\Workspaces\Backend\ToolbarItems\WorkspaceSelectorToolbarItem\getAdditionalAttributes
‪getAdditionalAttributes()
Definition: WorkspaceSelectorToolbarItem.php:109
‪TYPO3\CMS\Workspaces\Backend\ToolbarItems\WorkspaceSelectorToolbarItem\getIndex
‪getIndex()
Definition: WorkspaceSelectorToolbarItem.php:125