TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
WorkspaceSelectorToolbarItem.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Workspaces\Backend\ToolbarItems;
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  $title = htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:toolbarItems.workspace'));
75  $icon = $this->iconFactory->getIcon('apps-toolbar-menu-workspace', Icon::SIZE_SMALL)->render('inline');
76  return '
77  <span class="toolbar-item-icon" title="' . $title . '">' . $icon . '</span>
78  <span class="toolbar-item-title">' . $title . '</span>
79  ';
80  }
81 
87  public function getDropDown()
88  {
89  $backendUser = $this->getBackendUser();
90  $languageService = $this->getLanguageService();
91 
92  $index = 0;
93  $activeWorkspace = (int)$backendUser->workspace;
94  $stateCheckedIcon = $this->iconFactory->getIcon('status-status-checked', Icon::SIZE_SMALL)->render();
95  $stateUncheckedIcon = '<span title="' . htmlspecialchars($languageService->getLL('bookmark_inactive')) . '">' . $this->iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>';
96  $workspaceSections = [
97  'top' => [],
98  'items' => [],
99  ];
100 
101  foreach ($this->availableWorkspaces as $workspaceId => $label) {
102  $workspaceId = (int)$workspaceId;
103  $iconState = ($workspaceId === $activeWorkspace ? $stateCheckedIcon : $stateUncheckedIcon);
104  $classValue = ($workspaceId === $activeWorkspace ? 'selected' : '');
105  $sectionName = ($index++ === 0 ? 'top' : 'items');
106  $workspaceSections[$sectionName][] = '
107  <div class="dropdown-table-row t3js-workspace-item ' . $classValue . '">
108  <div class="dropdown-table-column dropdown-table-icon">
109  ' . $iconState . '
110  </div>
111  <div class="dropdown-table-column">
112  <a href="' . htmlspecialchars(\TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl('main', ['changeWorkspace' => $workspaceId])) . '" data-workspaceid="' . $workspaceId . '" class="t3js-workspaces-switchlink">
113  ' . htmlspecialchars($label) . '
114  </a>
115  </div>
116  </div>
117  ';
118  }
119 
120  if (!empty($workspaceSections['top'])) {
121  // Add the "Go to workspace module" link
122  // if there is at least one icon on top and if the access rights are there
123  if ($backendUser->check('modules', 'web_WorkspacesWorkspaces')) {
124  $workspaceSections['top'][] = '
125  <div class="dropdown-table-row">
126  <div class="dropdown-table-column dropdown-table-icon">
127  ' . $stateUncheckedIcon . '
128  </div>
129  <div class="dropdown-table-column">
130  <a href="#" target="list_frame" data-module="web_WorkspacesWorkspaces" class="t3js-workspaces-modulelink">
131  ' . htmlspecialchars($languageService->getLL('bookmark_workspace')) . '
132  </a>
133  </div>
134  </div>
135  ';
136  }
137  } else {
138  // no items on top (= no workspace to work in)
139  $workspaceSections['top'][] = '
140  <div class="dropdown-table-row">
141  <div class="dropdown-table-column dropdown-table-icon">
142  ' . $stateUncheckedIcon . '
143  </div>
144  <div class="dropdown-table-column">
145  ' . htmlspecialchars($languageService->getLL('bookmark_noWSfound')) . '
146  </div>
147  </div>
148  ';
149  }
150 
151  $workspaceMenu = [
152  '<h3 class="dropdown-headline">' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:toolbarItems.workspace')) . '</h3>',
153  '<hr>',
154  '<div class="dropdown-table">' . implode(LF, $workspaceSections['top']) . '</div>',
155  (!empty($workspaceSections['items']) ? '<hr>' : ''),
156  '<div class="dropdown-table">' . implode(LF, $workspaceSections['items']) . '</div>',
157  ];
158 
159  return implode(LF, $workspaceMenu);
160  }
161 
167  public function getAdditionalAttributes()
168  {
169  return [];
170  }
171 
177  public function hasDropDown()
178  {
179  return !empty($this->availableWorkspaces);
180  }
181 
187  public function getIndex()
188  {
189  return 40;
190  }
191 
197  protected function getBackendUser()
198  {
199  return $GLOBALS['BE_USER'];
200  }
201 
207  protected function getPageRenderer()
208  {
209  return GeneralUtility::makeInstance(PageRenderer::class);
210  }
211 
217  protected function getLanguageService()
218  {
219  return $GLOBALS['LANG'];
220  }
221 }
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static makeInstance($className,...$constructorArguments)