TYPO3 CMS  TYPO3_8-7
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 
28 {
33 
37  public function __construct()
38  {
39  $this->availableWorkspaces = GeneralUtility::makeInstance(WorkspaceService::class)
40  ->getAvailableWorkspaces();
41 
42  $pageRenderer = $this->getPageRenderer();
43  $pageRenderer->addInlineLanguageLabel('Workspaces.workspaceTitle', WorkspaceService::getWorkspaceTitle($this->getBackendUser()->workspace));
44  $pageRenderer->loadRequireJsModule('TYPO3/CMS/Workspaces/Toolbar/WorkspacesMenu');
45  }
46 
52  public function checkAccess()
53  {
54  return count($this->availableWorkspaces) > 1;
55  }
56 
62  public function getItem()
63  {
64  if (empty($this->availableWorkspaces)) {
65  return '';
66  }
67  return $this->getFluidTemplateObject('ToolbarItem.html')->render();
68  }
69 
75  public function getDropDown()
76  {
77  $topItem = null;
78  $additionalItems = [];
79  $backendUser = $this->getBackendUser();
80  $view = $this->getFluidTemplateObject('DropDown.html');
81  $activeWorkspace = (int)$backendUser->workspace;
82  foreach ($this->availableWorkspaces as $workspaceId => $label) {
83  $workspaceId = (int)$workspaceId;
84  $item = [
85  'isActive' => $workspaceId === $activeWorkspace,
86  'label' => $label,
87  'link' => BackendUtility::getModuleUrl('main', ['changeWorkspace' => $workspaceId]),
88  'workspaceId' => $workspaceId
89  ];
90  if ($topItem === null) {
91  $topItem = $item;
92  } else {
93  $additionalItems[] = $item;
94  }
95  }
96 
97  // Add the "Go to workspace module" link
98  // if there is at least one icon on top and if the access rights are there
99  if ($topItem !== null && $backendUser->check('modules', 'web_WorkspacesWorkspaces')) {
100  $view->assign('showLinkToModule', true);
101  }
102  $view->assign('topItem', $topItem);
103  $view->assign('additionalItems', $additionalItems);
104  return $view->render();
105  }
106 
112  public function getAdditionalAttributes()
113  {
114  return [];
115  }
116 
122  public function hasDropDown()
123  {
124  return !empty($this->availableWorkspaces);
125  }
126 
132  public function getIndex()
133  {
134  return 40;
135  }
136 
142  protected function getBackendUser()
143  {
144  return $GLOBALS['BE_USER'];
145  }
146 
152  protected function getPageRenderer()
153  {
154  return GeneralUtility::makeInstance(PageRenderer::class);
155  }
156 
163  protected function getFluidTemplateObject(string $filename): StandaloneView
164  {
165  $view = GeneralUtility::makeInstance(StandaloneView::class);
166  $view->setLayoutRootPaths(['EXT:workspaces/Resources/Private/Layouts']);
167  $view->setPartialRootPaths([
168  'EXT:backend/Resources/Private/Partials/ToolbarItems',
169  'EXT:workspaces/Resources/Private/Partials/ToolbarItems'
170  ]);
171  $view->setTemplateRootPaths(['EXT:workspaces/Resources/Private/Templates/ToolbarItems']);
172 
173  $view->setTemplate($filename);
174 
175  $view->getRequest()->setControllerExtensionName('Workspaces');
176  return $view;
177  }
178 }
static makeInstance($className,... $constructorArguments)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']