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