Skip to content

Commit

Permalink
[TASK] Reload topbar when sys_workspace records are changed
Browse files Browse the repository at this point in the history
This patch fixed a long existing issue regarding workspaces. If a
workspace is either created, updated or deleted, the topbar menu gets
reloaded to update the workspace menu now.

Resolves: #91948
Releases: master, 10.4
Change-Id: I316994c209d3bebc0e72e8e7ad956c5cf30502c9
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/65207
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
  • Loading branch information
andreaskienast committed Aug 8, 2020
1 parent 177ccb8 commit fecef67
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 11 deletions.
Expand Up @@ -16,6 +16,7 @@ import {AjaxResponse} from 'TYPO3/CMS/Core/Ajax/AjaxResponse';
import AjaxRequest = require('TYPO3/CMS/Core/Ajax/AjaxRequest');
import ModuleMenu = require('TYPO3/CMS/Backend/ModuleMenu');
import Viewport = require('TYPO3/CMS/Backend/Viewport');
import RegularEvent = require('TYPO3/CMS/Core/Event/RegularEvent');

enum Identifiers {
containerSelector = '#typo3-cms-workspaces-backend-toolbaritems-workspaceselectortoolbaritem',
Expand Down Expand Up @@ -46,6 +47,18 @@ class WorkspacesMenu {
}
}

private static updateWorkspaceState() {
// This is a poor-mans state update in case the current active workspace has been renamed
const selectedWorkspaceLink: HTMLElement = document.querySelector(Identifiers.containerSelector + ' .t3js-workspace-item.selected .t3js-workspaces-switchlink');
if (selectedWorkspaceLink !== null) {
const workspaceId = parseInt(selectedWorkspaceLink.dataset.workspaceid, 10);
const title = selectedWorkspaceLink.innerText.trim();

top.TYPO3.configuration.inWorkspace = workspaceId !== 0;
top.TYPO3.Backend.workspaceTitle = top.TYPO3.configuration.inWorkspace ? title : '';
}
}

/**
* adds the workspace title to the toolbar next to the username
*
Expand All @@ -62,11 +75,13 @@ class WorkspacesMenu {
}
}

private static updateBackendContext(title: string = ''): void {
private static updateBackendContext(): void {
let topBarTitle = '';
WorkspacesMenu.updateWorkspaceState();

if (TYPO3.configuration.inWorkspace) {
$('body').addClass(Classes.workspaceBodyClass);
topBarTitle = title || TYPO3.lang['Workspaces.workspaceTitle'];
topBarTitle = top.TYPO3.Backend.workspaceTitle || TYPO3.lang['Workspaces.workspaceTitle'];
} else {
$('body').removeClass(Classes.workspaceBodyClass);
}
Expand All @@ -79,21 +94,22 @@ class WorkspacesMenu {
this.initializeEvents();
WorkspacesMenu.updateBackendContext();
});

new RegularEvent('typo3:datahandler:delete', (e: CustomEvent): void => {
const payload = e.detail.payload;
if (payload.table === 'sys_workspace' && payload.action === 'delete' && payload.hasErrors === false) {
Viewport.Topbar.refresh();
}
}).bindTo(document);
}

/**
* Changes the data in the module menu and the updates the backend context
* This method is also used in the workspaces backend module.
*
* @param {Number} id the workspace ID
* @param {String} title the workspace title
*/
public performWorkspaceSwitch(id: number, title: string): void {
top.TYPO3.Backend.workspaceTitle = title;
top.TYPO3.configuration.inWorkspace = id !== 0;

WorkspacesMenu.updateBackendContext(title);

public performWorkspaceSwitch(id: number): void {
// first remove all checks, then set the check in front of the selected workspace
const stateActiveClass = 'fa fa-check';
const stateInactiveClass = 'fa fa-empty-empty';
Expand All @@ -111,6 +127,8 @@ class WorkspacesMenu {
.removeClass(stateInactiveClass)
.addClass(stateActiveClass);
$menuItem.addClass('selected');

WorkspacesMenu.updateBackendContext();
}

private initializeEvents(): void {
Expand All @@ -135,7 +153,7 @@ class WorkspacesMenu {
data.workspaceId = 0;
}

this.performWorkspaceSwitch(parseInt(data.workspaceId, 10), data.title);
this.performWorkspaceSwitch(parseInt(data.workspaceId, 10));

// append the returned page ID to the current module URL
if (data.pageId) {
Expand Down
13 changes: 13 additions & 0 deletions typo3/sysext/workspaces/Classes/Hook/DataHandlerHook.php
Expand Up @@ -326,10 +326,18 @@ public function processCmdmap_postProcess($command, $table, $id, $value, DataHan
$this->resetStageOfElements((int)$id);
} elseif ($table === WorkspaceService::TABLE_WORKSPACE) {
$this->flushWorkspaceElements((int)$id);
$this->emitUpdateTopbarSignal();
}
}
}

public function processDatamap_afterAllOperations(DataHandler $dataHandler): void
{
if (isset($dataHandler->datamap[WorkspaceService::TABLE_WORKSPACE])) {
$this->emitUpdateTopbarSignal();
}
}

/**
* Hook for \TYPO3\CMS\Core\DataHandling\DataHandler::moveRecord that cares about
* moving records that are *not* in the live workspace
Expand Down Expand Up @@ -1451,6 +1459,11 @@ public function getCommandMap(DataHandler $dataHandler): CommandMap
);
}

protected function emitUpdateTopbarSignal(): void
{
BackendUtility::setUpdateSignal('updateTopbar');
}

/**
* Returns all fieldnames from a table which have the unique evaluation type set.
*
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions typo3/sysext/workspaces/ext_localconf.php
Expand Up @@ -13,6 +13,7 @@

// register the hook to actually do the work within DataHandler
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processCmdmapClass']['workspaces'] = \TYPO3\CMS\Workspaces\Hook\DataHandlerHook::class;
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass']['workspaces'] = \TYPO3\CMS\Workspaces\Hook\DataHandlerHook::class;
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['moveRecordClass']['version'] = \TYPO3\CMS\Workspaces\Hook\DataHandlerHook::class;
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['viewOnClickClass']['workspaces'] = \TYPO3\CMS\Workspaces\Hook\BackendUtilityHook::class;
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/alt_doc.php']['makeEditForm_accessCheck']['workspaces'] = \TYPO3\CMS\Workspaces\Hook\BackendUtilityHook::class . '->makeEditForm_accessCheck';
Expand Down

0 comments on commit fecef67

Please sign in to comment.