‪TYPO3CMS  9.5
WorkspaceSelectorToolbarItem.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
23 
30 {
34  protected ‪$availableWorkspaces;
35 
39  public function ‪__construct()
40  {
41  $this->availableWorkspaces = GeneralUtility::makeInstance(WorkspaceService::class)
42  ->getAvailableWorkspaces();
43 
44  $pageRenderer = $this->‪getPageRenderer();
45  $pageRenderer->addInlineLanguageLabel('Workspaces.workspaceTitle', ‪WorkspaceService::getWorkspaceTitle($this->‪getBackendUser()->workspace));
46  $pageRenderer->loadRequireJsModule('TYPO3/CMS/Workspaces/Toolbar/WorkspacesMenu');
47  }
48 
54  public function ‪checkAccess()
55  {
56  return count($this->availableWorkspaces) > 1;
57  }
58 
64  public function ‪getItem()
65  {
66  if (empty($this->availableWorkspaces)) {
67  return '';
68  }
69  return $this->‪getFluidTemplateObject('ToolbarItem.html')->‪render();
70  }
71 
77  public function ‪getDropDown()
78  {
79  $topItem = null;
80  $additionalItems = [];
81  $backendUser = $this->‪getBackendUser();
82  $view = $this->‪getFluidTemplateObject('DropDown.html');
83  $activeWorkspace = (int)$backendUser->workspace;
84  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
85  foreach ($this->availableWorkspaces as $workspaceId => $label) {
86  $workspaceId = (int)$workspaceId;
87  $item = [
88  'isActive' => $workspaceId === $activeWorkspace,
89  'label' => $label,
90  'link' => (string)$uriBuilder->buildUriFromRoute('main', ['changeWorkspace' => $workspaceId]),
91  'workspaceId' => $workspaceId
92  ];
93  if ($topItem === null) {
94  $topItem = $item;
95  } else {
96  $additionalItems[] = $item;
97  }
98  }
99 
100  // Add the "Go to workspace module" link
101  // if there is at least one icon on top and if the access rights are there
102  if ($topItem !== null && $backendUser->check('modules', 'web_WorkspacesWorkspaces')) {
103  $view->assign('showLinkToModule', true);
104  }
105  $view->assign('topItem', $topItem);
106  $view->assign('additionalItems', $additionalItems);
107  return $view->render();
108  }
109 
115  public function ‪getAdditionalAttributes()
116  {
117  return [];
118  }
119 
125  public function ‪hasDropDown()
126  {
127  return !empty($this->availableWorkspaces);
128  }
129 
135  public function ‪getIndex()
136  {
137  return 40;
138  }
139 
145  protected function ‪getBackendUser()
146  {
147  return ‪$GLOBALS['BE_USER'];
148  }
149 
155  protected function ‪getPageRenderer()
156  {
157  return GeneralUtility::makeInstance(PageRenderer::class);
158  }
159 
166  protected function ‪getFluidTemplateObject(string $filename): ‪StandaloneView
167  {
168  $view = GeneralUtility::makeInstance(StandaloneView::class);
169  $view->setLayoutRootPaths(['EXT:workspaces/Resources/Private/Layouts']);
170  $view->setPartialRootPaths([
171  'EXT:backend/Resources/Private/Partials/ToolbarItems',
172  'EXT:workspaces/Resources/Private/Partials/ToolbarItems'
173  ]);
174  $view->setTemplateRootPaths(['EXT:workspaces/Resources/Private/Templates/ToolbarItems']);
175 
176  $view->setTemplate($filename);
177 
178  $view->getRequest()->setControllerExtensionName('Workspaces');
179  return $view;
180  }
181 }
‪TYPO3\CMS\Workspaces\Backend\ToolbarItems
Definition: WorkspaceSelectorToolbarItem.php:2
‪TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface
Definition: ToolbarItemInterface.php:24
‪TYPO3\CMS\Workspaces\Backend\ToolbarItems\WorkspaceSelectorToolbarItem\checkAccess
‪bool checkAccess()
Definition: WorkspaceSelectorToolbarItem.php:53
‪TYPO3\CMS\Workspaces\Backend\ToolbarItems\WorkspaceSelectorToolbarItem\__construct
‪__construct()
Definition: WorkspaceSelectorToolbarItem.php:38
‪TYPO3\CMS\Workspaces\Backend\ToolbarItems\WorkspaceSelectorToolbarItem
Definition: WorkspaceSelectorToolbarItem.php:30
‪TYPO3\CMS\Workspaces\Backend\ToolbarItems\WorkspaceSelectorToolbarItem\getBackendUser
‪TYPO3 CMS Core Authentication BackendUserAuthentication getBackendUser()
Definition: WorkspaceSelectorToolbarItem.php:144
‪TYPO3\CMS\Workspaces\Backend\ToolbarItems\WorkspaceSelectorToolbarItem\getItem
‪string getItem()
Definition: WorkspaceSelectorToolbarItem.php:63
‪TYPO3\CMS\Core\Page\PageRenderer
Definition: PageRenderer.php:35
‪TYPO3\CMS\Workspaces\Backend\ToolbarItems\WorkspaceSelectorToolbarItem\$availableWorkspaces
‪array $availableWorkspaces
Definition: WorkspaceSelectorToolbarItem.php:33
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:35
‪TYPO3\CMS\Workspaces\Backend\ToolbarItems\WorkspaceSelectorToolbarItem\getDropDown
‪string getDropDown()
Definition: WorkspaceSelectorToolbarItem.php:76
‪TYPO3\CMS\Workspaces\Backend\ToolbarItems\WorkspaceSelectorToolbarItem\getFluidTemplateObject
‪StandaloneView getFluidTemplateObject(string $filename)
Definition: WorkspaceSelectorToolbarItem.php:165
‪TYPO3\CMS\Workspaces\Backend\ToolbarItems\WorkspaceSelectorToolbarItem\getAdditionalAttributes
‪array getAdditionalAttributes()
Definition: WorkspaceSelectorToolbarItem.php:114
‪TYPO3\CMS\Workspaces\Service\WorkspaceService
Definition: WorkspaceService.php:34
‪TYPO3\CMS\Workspaces\Backend\ToolbarItems\WorkspaceSelectorToolbarItem\hasDropDown
‪bool hasDropDown()
Definition: WorkspaceSelectorToolbarItem.php:124
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:32
‪TYPO3\CMS\Workspaces\Backend\ToolbarItems\WorkspaceSelectorToolbarItem\getIndex
‪int getIndex()
Definition: WorkspaceSelectorToolbarItem.php:134
‪$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:45
‪TYPO3\CMS\Workspaces\Backend\ToolbarItems\WorkspaceSelectorToolbarItem\getPageRenderer
‪PageRenderer getPageRenderer()
Definition: WorkspaceSelectorToolbarItem.php:154
‪TYPO3\CMS\Workspaces\Service\WorkspaceService\getWorkspaceTitle
‪static string getWorkspaceTitle($wsId)
Definition: WorkspaceService.php:107