TYPO3 CMS  TYPO3_7-6
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  protected $iconFactory;
38 
42  public function __construct()
43  {
45  $wsService = GeneralUtility::makeInstance(WorkspaceService::class);
46  $this->availableWorkspaces = $wsService->getAvailableWorkspaces();
47 
48  $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
49  $pageRenderer = $this->getPageRenderer();
50  $pageRenderer->addInlineLanguageLabel('Workspaces.workspaceTitle', WorkspaceService::getWorkspaceTitle($this->getBackendUser()->workspace));
51  $pageRenderer->loadRequireJsModule('TYPO3/CMS/Workspaces/Toolbar/WorkspacesMenu');
52  }
53 
59  public function checkAccess()
60  {
61  return count($this->availableWorkspaces) > 1;
62  }
63 
69  public function getItem()
70  {
71  if (empty($this->availableWorkspaces)) {
72  return '';
73  }
74 
75  return '<span title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:toolbarItems.workspace', true) . '">'
76  . $this->iconFactory->getIcon('apps-toolbar-menu-workspace', Icon::SIZE_SMALL)->render('inline') . '</span>';
77  }
78 
84  public function getDropDown()
85  {
86  $backendUser = $this->getBackendUser();
87  $languageService = $this->getLanguageService();
88 
89  $index = 0;
90  $activeWorkspace = (int)$backendUser->workspace;
91  $stateCheckedIcon = $this->iconFactory->getIcon('status-status-checked', Icon::SIZE_SMALL)->render();
92  $stateUncheckedIcon = '<span title="' . $languageService->getLL('bookmark_inactive', true) . '">' . $this->iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>';
93  $workspaceSections = [
94  'top' => [],
95  'items' => [],
96  ];
97 
98  foreach ($this->availableWorkspaces as $workspaceId => $label) {
99  $workspaceId = (int)$workspaceId;
100  $iconState = ($workspaceId === $activeWorkspace ? $stateCheckedIcon : $stateUncheckedIcon);
101  $classValue = ($workspaceId === $activeWorkspace ? ' class="selected"' : '');
102  $sectionName = ($index++ === 0 ? 'top' : 'items');
103  $workspaceSections[$sectionName][] = '<li' . $classValue . '>'
104  . '<a href="' . htmlspecialchars(\TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl('main', ['changeWorkspace' => $workspaceId])) . '" data-workspaceid="' . $workspaceId . '" class="dropdown-list-link tx-workspaces-switchlink">'
105  . $iconState . ' ' . htmlspecialchars($label)
106  . '</a></li>';
107  }
108 
109  if (!empty($workspaceSections['top'])) {
110  // Add the "Go to workspace module" link
111  // if there is at least one icon on top and if the access rights are there
112  if ($backendUser->check('modules', 'web_WorkspacesWorkspaces')) {
113  $workspaceSections['top'][] = '<li><a target="content" data-module="web_WorkspacesWorkspaces" class="dropdown-list-link tx-workspaces-modulelink">'
114  . $stateUncheckedIcon . ' ' . $languageService->getLL('bookmark_workspace', true)
115  . '</a></li>';
116  }
117  } else {
118  // no items on top (= no workspace to work in)
119  $workspaceSections['top'][] = '<li>' . $stateUncheckedIcon . ' ' . $languageService->getLL('bookmark_noWSfound', true) . '</li>';
120  }
121 
122  $workspaceMenu = [
123  '<ul class="dropdown-list">' ,
124  implode(LF, $workspaceSections['top']),
125  (!empty($workspaceSections['items']) ? '<li class="divider"></li>' : ''),
126  implode(LF, $workspaceSections['items']),
127  '</ul>'
128  ];
129 
130  return implode(LF, $workspaceMenu);
131  }
132 
138  public function getAdditionalAttributes()
139  {
140  return [];
141  }
142 
148  public function hasDropDown()
149  {
150  return !empty($this->availableWorkspaces);
151  }
152 
158  public function getIndex()
159  {
160  return 40;
161  }
162 
168  protected function getBackendUser()
169  {
170  return $GLOBALS['BE_USER'];
171  }
172 
178  protected function getPageRenderer()
179  {
180  return GeneralUtility::makeInstance(PageRenderer::class);
181  }
182 
188  protected function getLanguageService()
189  {
190  return $GLOBALS['LANG'];
191  }
192 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']