[TASK] Remove compat layer for backend module
[Packages/TYPO3.CMS.git] / typo3 / sysext / workspaces / Classes / ExtDirect / WorkspaceSelectorToolbarItem.php
1 <?php
2 namespace TYPO3\CMS\Workspaces\ExtDirect;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2007-2013 Ingo Renner <ingo@typo3.org>
8 * (c) 2010-2013 Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces)
9 * All rights reserved
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 * A copy is found in the textfile GPL.txt and important notices to the license
20 * from the author is found in LICENSE.txt distributed with these scripts.
21 *
22 *
23 * This script is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * This copyright notice MUST APPEAR in all copies of the script!
29 ***************************************************************/
30
31 if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_AJAX) {
32 require_once \TYPO3\CMS\Core\Extension\ExtensionManager::extPath('backend') . 'Classes/Toolbar/ToolbarItemHookInterface.php';
33 }
34
35 /**
36 * class to render the workspace selector
37 *
38 * @author Ingo Renner <ingo@typo3.org>
39 */
40 class WorkspaceSelectorToolbarItem implements \TYPO3\CMS\Backend\Toolbar\ToolbarItemHookInterface {
41
42 protected $changeWorkspace;
43
44 protected $changeWorkspacePreview;
45
46 /**
47 * reference back to the backend object
48 *
49 * @var \TYPO3\CMS\Backend\Controller\BackendController
50 */
51 protected $backendReference;
52
53 protected $checkAccess = NULL;
54
55 /**
56 * constructor
57 *
58 * @param \TYPO3\CMS\Backend\Controller\BackendController TYPO3 backend object reference
59 */
60 public function __construct(\TYPO3\CMS\Backend\Controller\BackendController &$backendReference = NULL) {
61 $this->backendReference = $backendReference;
62 $this->changeWorkspace = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('changeWorkspace');
63 $this->changeWorkspacePreview = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('changeWorkspacePreview');
64 $pageRenderer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('t3lib_pageRenderer');
65 $this->backendReference->addJavaScript('TYPO3.Workspaces = { workspaceTitle : \'' . addslashes(\Tx_Workspaces_Service_Workspaces::getWorkspaceTitle($GLOBALS['BE_USER']->workspace)) . '\'};
66 ');
67 }
68
69 /**
70 * checks whether the user has access to this toolbar item
71 *
72 * @see typo3/alt_shortcut.php
73 * @return boolean TRUE if user has access, FALSE if not
74 */
75 public function checkAccess() {
76 if (\t3lib_extMgm::isLoaded('workspaces')) {
77 if ($this->checkAccess == NULL) {
78 $availableWorkspaces = \Tx_Workspaces_Service_Workspaces::getAvailableWorkspaces();
79 if (count($availableWorkspaces) > 0) {
80 $this->checkAccess = TRUE;
81 } else {
82 $this->checkAccess = FALSE;
83 }
84 }
85 return $this->checkAccess;
86 }
87 return FALSE;
88 }
89
90 /**
91 * Creates the selector for workspaces
92 *
93 * @return string workspace selector as HTML select
94 */
95 public function render() {
96 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:toolbarItems.workspace', TRUE);
97 $this->addJavascriptToBackend();
98 $availableWorkspaces = \Tx_Workspaces_Service_Workspaces::getAvailableWorkspaces();
99 $workspaceMenu = array();
100 $stateCheckedIcon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('status-status-checked');
101 $stateUncheckedIcon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('empty-empty', array(
102 'title' => $GLOBALS['LANG']->getLL('bookmark_inactive')
103 ));
104 $workspaceMenu[] = '<a href="#" class="toolbar-item">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('apps-toolbar-menu-workspace', array('title' => $title)) . '</a>';
105 $workspaceMenu[] = '<ul class="toolbar-item-menu" style="display: none;">';
106 if (count($availableWorkspaces)) {
107 foreach ($availableWorkspaces as $workspaceId => $label) {
108 $selected = '';
109 $icon = $stateUncheckedIcon;
110 if ((int) $GLOBALS['BE_USER']->workspace === $workspaceId) {
111 $selected = ' class="selected"';
112 $icon = $stateCheckedIcon;
113 }
114 $workspaceMenu[] = '<li' . $selected . '>' . '<a href="backend.php?changeWorkspace=' . intval($workspaceId) . '" id="ws-' . intval($workspaceId) . '" class="ws">' . $icon . ' ' . htmlspecialchars($label) . '</a></li>';
115 }
116 } else {
117 $workspaceMenu[] = '<li>' . $stateUncheckedIcon . ' ' . $GLOBALS['LANG']->getLL('bookmark_noWSfound', TRUE) . '</li>';
118 }
119 if ($GLOBALS['BE_USER']->check('modules', 'web_WorkspacesWorkspaces')) {
120 // go to workspace module link
121 $workspaceMenu[] = '<li class="divider">' . $stateUncheckedIcon . ' ' . '<a href="javascript:top.goToModule(\'web_WorkspacesWorkspaces\');" target="content" id="goToWsModule">' . ' ' . $GLOBALS['LANG']->getLL('bookmark_workspace', TRUE) . '</a></li>';
122 }
123 $workspaceMenu[] = '</ul>';
124 return implode(LF, $workspaceMenu);
125 }
126
127 /**
128 * adds the necessary JavaScript to the backend
129 *
130 * @return void
131 */
132 protected function addJavascriptToBackend() {
133 $this->backendReference->addJavascriptFile(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('workspaces') . 'Resources/Public/JavaScript/workspacemenu.js');
134 }
135
136 /**
137 * returns additional attributes for the list item in the toolbar
138 *
139 * @return string list item HTML attibutes
140 */
141 public function getAdditionalAttributes() {
142 return ' id="workspace-selector-menu"';
143 }
144
145 }
146
147
148 if (!(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_AJAX)) {
149 $GLOBALS['TYPO3backend']->addToolbarItem('workSpaceSelector', 'TYPO3\\CMS\\Workspaces\\ExtDirect\\WorkspaceSelectorToolbarItem');
150 }
151 ?>