Skip to content

Commit

Permalink
[TASK] Use ModuleData API in ReviewController
Browse files Browse the repository at this point in the history
The ModuleData API, introduced in #96895,
is now used in the ReviewController.

Resolves: #96956
Related: #96895
Releases: main
Change-Id: Ie2e4ac3dab37c246183efb53910bb2cd1a774189
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/73591
Tested-by: core-ci <typo3@b13.com>
Tested-by: Stefan Bürk <stefan@buerk.tech>
Tested-by: Benni Mack <benni@typo3.org>
Tested-by: Oliver Bartsch <bo@cedev.de>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Oliver Bartsch <bo@cedev.de>
  • Loading branch information
o-ba committed Feb 18, 2022
1 parent fec7826 commit d585226
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 29 deletions.
6 changes: 3 additions & 3 deletions Build/Sources/TypeScript/workspaces/backend.ts
Expand Up @@ -414,7 +414,7 @@ class Backend extends Workspaces {
// Listen for depth changes
this.elements.$depthSelector.on('change', (e: JQueryEventObject): void => {
const depth = (<HTMLSelectElement>e.target).value;
Persistent.set('moduleData.workspaces.settings.depth', depth);
Persistent.set('moduleData.web_WorkspacesWorkspaces.depth', depth);
this.settings.depth = depth;
this.getWorkspaceInfos();
});
Expand All @@ -425,7 +425,7 @@ class Backend extends Workspaces {
// Listen for language changes
this.elements.$languageSelector.on('change', (e: JQueryEventObject): void => {
const $me = $(e.target);
Persistent.set('moduleData.workspaces.settings.language', $me.val());
Persistent.set('moduleData.web_WorkspacesWorkspaces.language', $me.val());
this.settings.language = $me.val();
this.sendRemoteRequest(
this.generateRemotePayload('getWorkspaceInfos', this.settings),
Expand All @@ -438,7 +438,7 @@ class Backend extends Workspaces {

this.elements.$stagesSelector.on('change', (e: JQueryEventObject): void => {
const stage = (<HTMLSelectElement>e.target).value;
Persistent.set('moduleData.workspaces.settings.stage', stage);
Persistent.set('moduleData.web_WorkspacesWorkspaces.stage', stage);
this.settings.stage = stage;
this.getWorkspaceInfos();
});
Expand Down
33 changes: 8 additions & 25 deletions typo3/sysext/workspaces/Classes/Controller/ReviewController.php
Expand Up @@ -58,6 +58,7 @@ public function __construct(
public function handleRequest(ServerRequestInterface $request): ResponseInterface
{
$queryParams = $request->getQueryParams();
$moduleData = $request->getAttribute('moduleData');
$pageUid = (int)($queryParams['id'] ?? 0);

$icons = [
Expand Down Expand Up @@ -106,6 +107,7 @@ public function handleRequest(ServerRequestInterface $request): ResponseInterfac
}
$workspaceIsAccessible = $backendUser->workspace !== WorkspaceService::LIVE_WORKSPACE_ID && $pageUid > 0;

$selectedLanguage = (string)$moduleData->get('language');
$view = $this->moduleTemplateFactory->create($request, 'typo3/cms-workspaces');
$view->assignMultiple([
'isAdmin' => $backendUser->isAdmin(),
Expand All @@ -116,13 +118,13 @@ public function handleRequest(ServerRequestInterface $request): ResponseInterfac
'pageTitle' => $pageTitle,
'activeWorkspaceUid' => $activeWorkspace,
'activeWorkspaceTitle' => $activeWorkspaceTitle,
'availableLanguages' => $this->getSystemLanguages($pageUid),
'availableLanguages' => $this->getSystemLanguages($pageUid, $selectedLanguage),
'availableStages' => $this->stagesService->getStagesForWSUser(),
'availableSelectStages' => $this->getAvailableSelectStages(),
'stageActions' => $this->getStageActions(),
'selectedLanguage' => $this->getLanguageSelection(),
'selectedDepth' => $this->getDepthSelection($pageUid),
'selectedStage' => $this->getStageSelection(),
'selectedLanguage' => $selectedLanguage,
'selectedDepth' => (int)$moduleData->get('depth', ($pageUid === 0 ? 999 : 1)),
'selectedStage' => (int)$moduleData->get('stage'),
'workspaceSwitched' => $workspaceSwitched,
]);
$view->setTitle(
Expand Down Expand Up @@ -243,24 +245,6 @@ protected function getModuleUri(int $pageUid, int $workspaceId = null): string
return (string)$this->uriBuilder->buildUriFromRoute('web_WorkspacesWorkspaces', $parameters);
}

protected function getLanguageSelection(): string
{
$moduleData = $this->getBackendUser()->getModuleData('workspaces') ?? [];
return (string)($moduleData['settings']['language'] ?? 'all');
}

protected function getDepthSelection(int $pageId): int
{
$moduleData = $this->getBackendUser()->getModuleData('workspaces') ?? [];
return (int)($moduleData['settings']['depth'] ?? ($pageId === 0 ? 999 : 1));
}

protected function getStageSelection(): int
{
$moduleData = $this->getBackendUser()->getModuleData('workspaces') ?? [];
return (int)($moduleData['settings']['stage'] ?? -99);
}

/**
* Returns true if at least one custom workspace next to live workspace exists.
*/
Expand All @@ -277,16 +261,15 @@ protected function customWorkspaceExists(array $workspaceList): bool
/**
* Gets all available system languages.
*/
protected function getSystemLanguages(int $pageId): array
protected function getSystemLanguages(int $pageId, string $selectedLanguage): array
{
$languages = $this->translationConfigurationProvider->getSystemLanguages($pageId);
if (isset($languages[-1])) {
$languages[-1]['uid'] = 'all';
}
$activeLanguage = $this->getLanguageSelection();
foreach ($languages as &$language) {
// needs to be strict type checking as this is not possible in fluid
if ((string)$language['uid'] === $activeLanguage) {
if ((string)$language['uid'] === $selectedLanguage) {
$language['active'] = true;
}
}
Expand Down
5 changes: 5 additions & 0 deletions typo3/sysext/workspaces/Configuration/Backend/Modules.php
Expand Up @@ -18,5 +18,10 @@
'target' => ReviewController::class . '::handleRequest',
],
],
'moduleData' => [
'language' => 'all',
'depth' => 1,
'stage' => -99,
],
],
];

0 comments on commit d585226

Please sign in to comment.