‪TYPO3CMS  11.5
AjaxController.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use Psr\Http\Message\ResponseInterface;
19 use Psr\Http\Message\ServerRequestInterface;
20 use TYPO3\CMS\Backend\Utility\BackendUtility;
25 
31 {
39  public function ‪switchWorkspaceAction(ServerRequestInterface $request): ResponseInterface
40  {
41  $page = [];
42  $parsedBody = $request->getParsedBody();
43  $queryParams = $request->getQueryParams();
44  $workspaceId = (int)($parsedBody['workspaceId'] ?? $queryParams['workspaceId']);
45  $pageId = (int)($parsedBody['pageId'] ?? $queryParams['pageId'] ?? 0);
46  $finalPageUid = 0;
47  $originalPageId = $pageId;
48 
49  $this->‪getBackendUser()->‪setWorkspace($workspaceId);
50 
51  while ($pageId) {
52  $page = BackendUtility::getRecordWSOL(
53  'pages',
54  $pageId,
55  '*',
56  ' AND pages.t3ver_wsid IN (0, ' . $workspaceId . ')'
57  );
58  if ($page) {
59  if ($this->‪getBackendUser()->doesUserHaveAccess($page, ‪Permission::PAGE_SHOW)) {
60  break;
61  }
62  } else {
63  $page = BackendUtility::getRecord('pages', $pageId);
64  }
65  $pageId = $page['pid'];
66  }
67 
68  if (isset($page['uid'])) {
69  $finalPageUid = (int)$page['uid'];
70  }
71 
72  $ajaxResponse = [
73  'title' => ‪WorkspaceService::getWorkspaceTitle($workspaceId),
74  'workspaceId' => $workspaceId,
75  'pageId' => ($finalPageUid && $originalPageId == $finalPageUid) ? null : $finalPageUid,
76  'pageModule' => $this->‪getPageModuleName(),
77  ];
78  return new ‪JsonResponse($ajaxResponse);
79  }
80 
87  protected function ‪getPageModuleName(): string
88  {
89  $backendUser = $this->‪getBackendUser();
90  $pageModule = trim($backendUser->getTSConfig()['options.']['overridePageModule'] ?? '');
91  $pageModule = BackendUtility::isModuleSetInTBE_MODULES($pageModule) ? $pageModule : 'web_layout';
92 
93  return $backendUser->check('modules', $pageModule) ? $pageModule : '';
94  }
95 
99  protected function ‪getBackendUser()
100  {
101  return ‪$GLOBALS['BE_USER'];
102  }
103 }
‪TYPO3\CMS\Workspaces\Controller\AjaxController\getPageModuleName
‪string getPageModuleName()
Definition: AjaxController.php:87
‪TYPO3\CMS\Workspaces\Controller\AjaxController\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: AjaxController.php:99
‪TYPO3\CMS\Workspaces\Controller\AjaxController\switchWorkspaceAction
‪ResponseInterface switchWorkspaceAction(ServerRequestInterface $request)
Definition: AjaxController.php:39
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:26
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\setWorkspace
‪setWorkspace($workspaceId)
Definition: BackendUserAuthentication.php:1916
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_SHOW
‪const PAGE_SHOW
Definition: Permission.php:35
‪TYPO3\CMS\Workspaces\Service\WorkspaceService
Definition: WorkspaceService.php:36
‪TYPO3\CMS\Core\Http\JsonResponse
Definition: JsonResponse.php:28
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Workspaces\Controller\AjaxController
Definition: AjaxController.php:31
‪TYPO3\CMS\Workspaces\Controller
Definition: AjaxController.php:16
‪TYPO3\CMS\Workspaces\Service\WorkspaceService\getWorkspaceTitle
‪static string getWorkspaceTitle($wsId)
Definition: WorkspaceService.php:120