‪TYPO3CMS  11.5
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 
20 use TYPO3\CMS\Core\Page\PageRenderer;
24 
31 {
35  protected ‪$availableWorkspaces;
36 
40  public function ‪__construct()
41  {
42  $currentWorkspace = $this->‪getBackendUser()->workspace;
43  $this->availableWorkspaces = GeneralUtility::makeInstance(WorkspaceService::class)
44  ->getAvailableWorkspaces();
45 
46  $pageRenderer = $this->‪getPageRenderer();
47  $pageRenderer->addInlineLanguageLabel('Workspaces.workspaceTitle', $currentWorkspace !== -99 ? ‪WorkspaceService::getWorkspaceTitle($currentWorkspace) : '');
48  $pageRenderer->loadRequireJsModule('TYPO3/CMS/Workspaces/Toolbar/WorkspacesMenu');
49  }
50 
56  public function ‪checkAccess()
57  {
58  return count($this->availableWorkspaces) > 1;
59  }
60 
66  public function ‪getItem()
67  {
68  if (empty($this->availableWorkspaces)) {
69  return '';
70  }
71  return $this->‪getFluidTemplateObject('ToolbarItem.html')->‪render();
72  }
73 
79  public function ‪getDropDown()
80  {
81  $topItem = null;
82  $additionalItems = [];
83  $backendUser = $this->‪getBackendUser();
84  $view = $this->‪getFluidTemplateObject('DropDown.html');
85  $activeWorkspace = (int)$backendUser->workspace;
86  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
87  foreach ($this->availableWorkspaces as $workspaceId => $label) {
88  $workspaceId = (int)$workspaceId;
89  $item = [
90  'isActive' => $workspaceId === $activeWorkspace,
91  'label' => $label,
92  'link' => (string)$uriBuilder->buildUriFromRoute('main', ['changeWorkspace' => $workspaceId]),
93  'workspaceId' => $workspaceId,
94  ];
95  if ($topItem === null) {
96  $topItem = $item;
97  } else {
98  $additionalItems[] = $item;
99  }
100  }
101 
102  // Add the "Go to workspace module" link
103  // if there is at least one icon on top and if the access rights are there
104  if ($topItem !== null && $backendUser->check('modules', 'web_WorkspacesWorkspaces')) {
105  $view->assign('showLinkToModule', true);
106  }
107  $view->assign('topItem', $topItem);
108  $view->assign('additionalItems', $additionalItems);
109  return $view->render();
110  }
111 
117  public function ‪getAdditionalAttributes()
118  {
119  return [];
120  }
121 
127  public function ‪hasDropDown()
128  {
129  return !empty($this->availableWorkspaces);
130  }
131 
137  public function ‪getIndex()
138  {
139  return 40;
140  }
141 
147  protected function ‪getBackendUser()
148  {
149  return ‪$GLOBALS['BE_USER'];
150  }
151 
157  protected function ‪getPageRenderer()
158  {
159  return GeneralUtility::makeInstance(PageRenderer::class);
160  }
161 
168  protected function ‪getFluidTemplateObject(string $filename): ‪StandaloneView
169  {
170  $view = GeneralUtility::makeInstance(StandaloneView::class);
171  $view->setLayoutRootPaths(['EXT:workspaces/Resources/Private/Layouts']);
172  $view->setPartialRootPaths([
173  'EXT:backend/Resources/Private/Partials/ToolbarItems',
174  'EXT:workspaces/Resources/Private/Partials/ToolbarItems',
175  ]);
176  $view->setTemplateRootPaths(['EXT:workspaces/Resources/Private/Templates/ToolbarItems']);
177 
178  $view->setTemplate($filename);
179 
180  $view->getRequest()->setControllerExtensionName('Workspaces');
181  return $view;
182  }
183 }
‪TYPO3\CMS\Workspaces\Backend\ToolbarItems
Definition: WorkspaceSelectorToolbarItem.php:16
‪TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface
Definition: ToolbarItemInterface.php:22
‪TYPO3\CMS\Workspaces\Backend\ToolbarItems\WorkspaceSelectorToolbarItem\checkAccess
‪bool checkAccess()
Definition: WorkspaceSelectorToolbarItem.php:55
‪TYPO3\CMS\Workspaces\Backend\ToolbarItems\WorkspaceSelectorToolbarItem\__construct
‪__construct()
Definition: WorkspaceSelectorToolbarItem.php:39
‪TYPO3\CMS\Workspaces\Backend\ToolbarItems\WorkspaceSelectorToolbarItem
Definition: WorkspaceSelectorToolbarItem.php:31
‪TYPO3\CMS\Workspaces\Backend\ToolbarItems\WorkspaceSelectorToolbarItem\getBackendUser
‪TYPO3 CMS Core Authentication BackendUserAuthentication getBackendUser()
Definition: WorkspaceSelectorToolbarItem.php:146
‪TYPO3\CMS\Workspaces\Backend\ToolbarItems\WorkspaceSelectorToolbarItem\getItem
‪string getItem()
Definition: WorkspaceSelectorToolbarItem.php:65
‪TYPO3\CMS\Workspaces\Backend\ToolbarItems\WorkspaceSelectorToolbarItem\$availableWorkspaces
‪array $availableWorkspaces
Definition: WorkspaceSelectorToolbarItem.php:34
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:40
‪TYPO3\CMS\Workspaces\Backend\ToolbarItems\WorkspaceSelectorToolbarItem\getDropDown
‪string getDropDown()
Definition: WorkspaceSelectorToolbarItem.php:78
‪TYPO3\CMS\Workspaces\Backend\ToolbarItems\WorkspaceSelectorToolbarItem\getFluidTemplateObject
‪StandaloneView getFluidTemplateObject(string $filename)
Definition: WorkspaceSelectorToolbarItem.php:167
‪TYPO3\CMS\Workspaces\Backend\ToolbarItems\WorkspaceSelectorToolbarItem\getAdditionalAttributes
‪array getAdditionalAttributes()
Definition: WorkspaceSelectorToolbarItem.php:116
‪TYPO3\CMS\Workspaces\Service\WorkspaceService
Definition: WorkspaceService.php:36
‪TYPO3\CMS\Workspaces\Backend\ToolbarItems\WorkspaceSelectorToolbarItem\hasDropDown
‪bool hasDropDown()
Definition: WorkspaceSelectorToolbarItem.php:126
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:31
‪TYPO3\CMS\Workspaces\Backend\ToolbarItems\WorkspaceSelectorToolbarItem\getIndex
‪int getIndex()
Definition: WorkspaceSelectorToolbarItem.php:136
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Extbase\Mvc\View\ViewInterface\render
‪string render()
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Workspaces\Backend\ToolbarItems\WorkspaceSelectorToolbarItem\getPageRenderer
‪PageRenderer getPageRenderer()
Definition: WorkspaceSelectorToolbarItem.php:156
‪TYPO3\CMS\Workspaces\Service\WorkspaceService\getWorkspaceTitle
‪static string getWorkspaceTitle($wsId)
Definition: WorkspaceService.php:120