‪TYPO3CMS  10.4
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;
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']);
46  $finalPageUid = 0;
47  $originalPageId = $pageId;
48 
49  $this->‪getBackendUser()->‪setWorkspace($workspaceId);
50 
51  while ($pageId) {
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  ];
77  return new ‪JsonResponse($ajaxResponse);
78  }
79 
83  protected function ‪getBackendUser()
84  {
85  return ‪$GLOBALS['BE_USER'];
86  }
87 }
‪TYPO3\CMS\Workspaces\Controller\AjaxController\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: AjaxController.php:83
‪TYPO3\CMS\Workspaces\Controller\AjaxController\switchWorkspaceAction
‪ResponseInterface switchWorkspaceAction(ServerRequestInterface $request)
Definition: AjaxController.php:39
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:24
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\setWorkspace
‪setWorkspace($workspaceId)
Definition: BackendUserAuthentication.php:2186
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_SHOW
‪const PAGE_SHOW
Definition: Permission.php:33
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:75
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecordWSOL
‪static array getRecordWSOL( $table, $uid, $fields=' *', $where='', $useDeleteClause=true, $unsetMovePointers=false)
Definition: BackendUtility.php:139
‪TYPO3\CMS\Workspaces\Service\WorkspaceService
Definition: WorkspaceService.php:36
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecord
‪static array null getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
Definition: BackendUtility.php:95
‪TYPO3\CMS\Core\Http\JsonResponse
Definition: JsonResponse.php:26
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪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