‪TYPO3CMS  ‪main
AjaxController.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Http\Message\ResponseInterface;
21 use Psr\Http\Message\ServerRequestInterface;
24 use TYPO3\CMS\Backend\Utility\BackendUtility;
29 
35 #[AsController]
37 {
38  public function ‪__construct(
39  private readonly ‪WorkspaceService $workspaceService,
40  private readonly ‪ModuleProvider $moduleProvider,
41  ) {}
42 
47  public function ‪switchWorkspaceAction(ServerRequestInterface $request): ResponseInterface
48  {
49  $page = [];
50  $parsedBody = $request->getParsedBody();
51  $queryParams = $request->getQueryParams();
52  $workspaceId = (int)($parsedBody['workspaceId'] ?? $queryParams['workspaceId']);
53  $pageId = (int)($parsedBody['pageId'] ?? $queryParams['pageId'] ?? 0);
54  $finalPageUid = 0;
55  $originalPageId = $pageId;
56 
57  $this->‪getBackendUser()->setWorkspace($workspaceId);
58 
59  while ($pageId) {
60  $page = BackendUtility::getRecordWSOL(
61  'pages',
62  $pageId,
63  '*',
64  ' AND pages.t3ver_wsid IN (0, ' . $workspaceId . ')'
65  );
66  if ($page) {
67  if ($this->‪getBackendUser()->doesUserHaveAccess($page, ‪Permission::PAGE_SHOW)) {
68  break;
69  }
70  } else {
71  $page = BackendUtility::getRecord('pages', $pageId);
72  }
73  $pageId = $page['pid'];
74  }
75 
76  if (isset($page['uid'])) {
77  $finalPageUid = (int)$page['uid'];
78  }
79 
80  $ajaxResponse = [
81  'title' => $this->workspaceService->getWorkspaceTitle($workspaceId),
82  'workspaceId' => $workspaceId,
83  'pageId' => ($finalPageUid && $originalPageId == $finalPageUid) ? null : $finalPageUid,
84  'pageModule' => $this->moduleProvider->accessGranted('web_layout', $this->getBackendUser()) ? 'web_layout' : '',
85  ];
86  return new ‪JsonResponse($ajaxResponse);
87  }
88 
90  {
91  return ‪$GLOBALS['BE_USER'];
92  }
93 }
‪TYPO3\CMS\Workspaces\Controller\AjaxController\switchWorkspaceAction
‪switchWorkspaceAction(ServerRequestInterface $request)
Definition: AjaxController.php:47
‪TYPO3\CMS\Backend\Module\ModuleProvider
Definition: ModuleProvider.php:29
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:26
‪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:38
‪TYPO3\CMS\Core\Http\JsonResponse
Definition: JsonResponse.php:28
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Backend\Attribute\AsController
Definition: AsController.php:25
‪TYPO3\CMS\Workspaces\Controller\AjaxController\__construct
‪__construct(private readonly WorkspaceService $workspaceService, private readonly ModuleProvider $moduleProvider,)
Definition: AjaxController.php:38
‪TYPO3\CMS\Workspaces\Controller\AjaxController
Definition: AjaxController.php:37
‪TYPO3\CMS\Workspaces\Controller
Definition: AjaxController.php:18
‪TYPO3\CMS\Workspaces\Controller\AjaxController\getBackendUser
‪getBackendUser()
Definition: AjaxController.php:89