[TASK] Save pixels: hide Workspace toolbar item when unused 68/40368/5
authorFelix Kopp <felix-source@phorax.com>
Wed, 17 Jun 2015 15:21:37 +0000 (17:21 +0200)
committerMarkus Klein <markus.klein@typo3.org>
Thu, 18 Jun 2015 19:35:38 +0000 (21:35 +0200)
In use case where EXT: workspaces is installed and activated but no
additional Workspaces (sys_workspace) records are added TYPO3
should assume that Workspaces are unused. No permanently visible
button should sit in the topbar.

Resolves: #67568
Releases: master
Change-Id: I1a4bd40df79458690ce1c0d9e141dd71247d8cbf
Reviewed-on: http://review.typo3.org/40368
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/workspaces/Classes/Backend/ToolbarItems/WorkspaceSelectorToolbarItem.php

index a901c83..64d7343 100644 (file)
@@ -27,9 +27,18 @@ use TYPO3\CMS\Backend\Utility\IconUtility;
 class WorkspaceSelectorToolbarItem implements ToolbarItemInterface {
 
        /**
+        * @var array
+        */
+       protected $availableWorkspaces;
+
+       /**
         * Constructor
         */
        public function __construct() {
+               /** @var \TYPO3\CMS\Workspaces\Service\WorkspaceService $wsService */
+               $wsService = GeneralUtility::makeInstance(WorkspaceService::class);
+               $this->availableWorkspaces = $wsService->getAvailableWorkspaces();
+
                $pageRenderer = $this->getPageRenderer();
                $pageRenderer->addInlineLanguageLabel('Workspaces.workspaceTitle', WorkspaceService::getWorkspaceTitle($this->getBackendUser()->workspace));
                $pageRenderer->loadRequireJsModule('TYPO3/CMS/Workspaces/Toolbar/WorkspacesMenu');
@@ -41,15 +50,7 @@ class WorkspaceSelectorToolbarItem implements ToolbarItemInterface {
         * @return bool TRUE if user has access, FALSE if not
         */
        public function checkAccess() {
-               /** @var \TYPO3\CMS\Workspaces\Service\WorkspaceService $wsService */
-               $wsService = GeneralUtility::makeInstance(WorkspaceService::class);
-               $availableWorkspaces = $wsService->getAvailableWorkspaces();
-               if (count($availableWorkspaces) > 0) {
-                       $result = TRUE;
-               } else {
-                       $result = FALSE;
-               }
-               return $result;
+               return count($this->availableWorkspaces) > 1;
        }
 
        /**
@@ -58,6 +59,10 @@ class WorkspaceSelectorToolbarItem implements ToolbarItemInterface {
         * @return string HTML
         */
        public function getItem() {
+               if (empty($this->availableWorkspaces)) {
+                       return '';
+               }
+
                return IconUtility::getSpriteIcon(
                        'apps-toolbar-menu-workspace',
                        array(
@@ -66,14 +71,16 @@ class WorkspaceSelectorToolbarItem implements ToolbarItemInterface {
                );
        }
 
+       /**
+        * Get drop down
+        *
+        * @return string
+        */
        public function getDropDown() {
                $backendUser = $this->getBackendUser();
                $languageService = $this->getLanguageService();
 
                $index = 0;
-               /** @var WorkspaceService $wsService */
-               $wsService = GeneralUtility::makeInstance(WorkspaceService::class);
-               $availableWorkspaces = $wsService->getAvailableWorkspaces();
                $activeWorkspace = (int)$backendUser->workspace;
                $stateCheckedIcon = IconUtility::getSpriteIcon('status-status-checked');
                $stateUncheckedIcon = IconUtility::getSpriteIcon('empty-empty', array(
@@ -85,7 +92,7 @@ class WorkspaceSelectorToolbarItem implements ToolbarItemInterface {
                        'items' => array(),
                );
 
-               foreach ($availableWorkspaces as $workspaceId => $label) {
+               foreach ($this->availableWorkspaces as $workspaceId => $label) {
                        $workspaceId = (int)$workspaceId;
                        $iconState = ($workspaceId === $activeWorkspace ? $stateCheckedIcon : $stateUncheckedIcon);
                        $classValue = ($workspaceId === $activeWorkspace ? ' class="selected"' : '');
@@ -135,7 +142,7 @@ class WorkspaceSelectorToolbarItem implements ToolbarItemInterface {
         * @return bool
         */
        public function hasDropDown() {
-               return TRUE;
+               return !empty($this->availableWorkspaces);
        }
 
        /**