‪TYPO3CMS  9.5
AjaxController.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
17 use Psr\Http\Message\ResponseInterface;
18 use Psr\Http\Message\ServerRequestInterface;
24 
30 {
38  public function ‪switchWorkspaceAction(ServerRequestInterface $request): ResponseInterface
39  {
40  $parsedBody = $request->getParsedBody();
41  $queryParams = $request->getQueryParams();
42  $workspaceId = (int)($parsedBody['workspaceId'] ?? $queryParams['workspaceId']);
43  $pageId = (int)($parsedBody['pageId'] ?? $queryParams['pageId']);
44  $finalPageUid = 0;
45  $originalPageId = $pageId;
46 
47  $this->‪getBackendUser()->‪setWorkspace($workspaceId);
48 
49  while ($pageId) {
51  'pages',
52  $pageId,
53  '*',
54  ' AND pages.t3ver_wsid IN (0, ' . $workspaceId . ')'
55  );
56  if ($page) {
57  if ($this->‪getBackendUser()->doesUserHaveAccess($page, ‪Permission::PAGE_SHOW)) {
58  break;
59  }
60  } else {
61  $page = ‪BackendUtility::getRecord('pages', $pageId);
62  }
63  $pageId = $page['pid'];
64  }
65 
66  if (isset($page['uid'])) {
67  $finalPageUid = (int)$page['uid'];
68  }
69 
70  $ajaxResponse = [
71  'title' => ‪WorkspaceService::getWorkspaceTitle($workspaceId),
72  'workspaceId' => $workspaceId,
73  'pageId' => ($finalPageUid && $originalPageId == $finalPageUid) ? null : $finalPageUid
74  ];
75  return new ‪JsonResponse($ajaxResponse);
76  }
77 
81  protected function ‪getBackendUser()
82  {
83  return ‪$GLOBALS['BE_USER'];
84  }
85 }
‪TYPO3\CMS\Workspaces\Controller\AjaxController\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: AjaxController.php:81
‪TYPO3\CMS\Workspaces\Controller\AjaxController\switchWorkspaceAction
‪ResponseInterface switchWorkspaceAction(ServerRequestInterface $request)
Definition: AjaxController.php:38
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:23
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\setWorkspace
‪setWorkspace($workspaceId)
Definition: BackendUserAuthentication.php:2250
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:45
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_SHOW
‪const PAGE_SHOW
Definition: Permission.php:32
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:72
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecordWSOL
‪static array getRecordWSOL( $table, $uid, $fields=' *', $where='', $useDeleteClause=true, $unsetMovePointers=false)
Definition: BackendUtility.php:174
‪TYPO3\CMS\Workspaces\Service\WorkspaceService
Definition: WorkspaceService.php:34
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecord
‪static array null getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
Definition: BackendUtility.php:130
‪TYPO3\CMS\Core\Http\JsonResponse
Definition: JsonResponse.php:25
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Workspaces\Controller\AjaxController
Definition: AjaxController.php:30
‪TYPO3\CMS\Workspaces\Controller
Definition: AjaxController.php:2
‪TYPO3\CMS\Workspaces\Service\WorkspaceService\getWorkspaceTitle
‪static string getWorkspaceTitle($wsId)
Definition: WorkspaceService.php:107