TYPO3 CMS  TYPO3_6-2
WorkspaceSelectorToolbarItem.php
Go to the documentation of this file.
1 <?php
3 
18 
19 if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_AJAX) {
20  require_once \TYPO3\CMS\Core\Extension\ExtensionManager::extPath('backend') . 'Classes/Toolbar/ToolbarItemHookInterface.php';
21 }
22 
29 
30  protected $changeWorkspace;
31 
33 
39  protected $backendReference;
40 
41  protected $checkAccess = NULL;
42 
48  public function __construct(\TYPO3\CMS\Backend\Controller\BackendController &$backendReference = NULL) {
49  $this->backendReference = $backendReference;
50  $this->changeWorkspace = GeneralUtility::_GP('changeWorkspace');
51  $this->changeWorkspacePreview = GeneralUtility::_GP('changeWorkspacePreview');
52  $pageRenderer = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Page\\PageRenderer');
53  $this->backendReference->addJavaScript('TYPO3.Workspaces = { workspaceTitle : \'' . addslashes(\TYPO3\CMS\Workspaces\Service\WorkspaceService::getWorkspaceTitle($GLOBALS['BE_USER']->workspace)) . '\'};
54 ');
55  }
56 
62  public function checkAccess() {
63  if (!\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('workspaces')) {
64  return FALSE;
65  }
66 
67  if ($this->checkAccess == NULL) {
69  $wsService = GeneralUtility::makeInstance('TYPO3\\CMS\\Workspaces\\Service\\WorkspaceService');
70  $availableWorkspaces = $wsService->getAvailableWorkspaces();
71  if (count($availableWorkspaces) > 0) {
72  $this->checkAccess = TRUE;
73  } else {
74  $this->checkAccess = FALSE;
75  }
76  }
77  return $this->checkAccess;
78  }
79 
85  public function render() {
86  $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:toolbarItems.workspace', TRUE);
87  $this->addJavascriptToBackend();
88 
89  $index = 0;
91  $wsService = GeneralUtility::makeInstance('TYPO3\\CMS\\Workspaces\\Service\\WorkspaceService');
92  $availableWorkspaces = $wsService->getAvailableWorkspaces();
93  $activeWorkspace = (int)$GLOBALS['BE_USER']->workspace;
94  $stateCheckedIcon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('status-status-checked');
95  $stateUncheckedIcon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('empty-empty', array(
96  'title' => $GLOBALS['LANG']->getLL('bookmark_inactive')
97  ));
98 
99  $workspaceSections = array(
100  'top' => array(),
101  'items' => array(),
102  );
103 
104  foreach ($availableWorkspaces as $workspaceId => $label) {
105  $workspaceId = (int)$workspaceId;
106  $iconState = ($workspaceId === $activeWorkspace ? $stateCheckedIcon : $stateUncheckedIcon);
107  $classValue = ($workspaceId === $activeWorkspace ? ' class="selected"' : '');
108  $sectionName = ($index++ === 0 ? 'top' : 'items');
109  $workspaceSections[$sectionName][] = '<li' . $classValue . '>' . '<a href="backend.php?changeWorkspace=' . $workspaceId . '" id="ws-' . $workspaceId . '" class="ws">' . $iconState . ' ' . htmlspecialchars($label) . '</a></li>';
110  }
111 
112  if (count($workspaceSections['top']) > 0) {
113  // Go to workspace module link
114  if ($GLOBALS['BE_USER']->check('modules', 'web_WorkspacesWorkspaces')) {
115  $workspaceSections['top'][] = '<li>' . '<a href="javascript:top.goToModule(\'web_WorkspacesWorkspaces\');" target="content" id="goToWsModule">' . $stateUncheckedIcon . ' ' . $GLOBALS['LANG']->getLL('bookmark_workspace', TRUE) . '</a></li>';
116  }
117  $workspaceSections['top'][] = '<li class="divider"></li>';
118  } else {
119  $workspaceSections['top'][] = '<li>' . $stateUncheckedIcon . ' ' . $GLOBALS['LANG']->getLL('bookmark_noWSfound', TRUE) . '</li>';
120  }
121 
122 
123  $workspaceMenu = array(
124  '<a href="#" class="toolbar-item">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('apps-toolbar-menu-workspace', array('title' => $title)) . '</a>',
125  '<div class="toolbar-item-menu" style="display: none">' ,
126  '<ul class="top">',
127  implode(LF, $workspaceSections['top']),
128  '</ul>',
129  '<ul class="items">',
130  implode(LF, $workspaceSections['items']),
131  '</ul>',
132  '</div>'
133  );
134 
135  return implode(LF, $workspaceMenu);
136  }
137 
143  protected function addJavascriptToBackend() {
144  $this->backendReference->addJavascriptFile(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('workspaces') . 'Resources/Public/JavaScript/workspacemenu.js');
145  }
146 
152  public function getAdditionalAttributes() {
153  return 'id="workspace-selector-menu"';
154  }
155 
156 }
157 
158 
159 if (!(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_AJAX)) {
160  $GLOBALS['TYPO3backend']->addToolbarItem('workSpaceSelector', 'TYPO3\\CMS\\Workspaces\\ExtDirect\\WorkspaceSelectorToolbarItem');
161 }
__construct(\TYPO3\CMS\Backend\Controller\BackendController &$backendReference=NULL)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]