‪TYPO3CMS  ‪main
ListController.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;
23 use TYPO3\CMS\Backend\Utility\BackendUtility;
26 
33 {
37  public function ‪mainAction(ServerRequestInterface $request): ResponseInterface
38  {
39  $parsedBody = $request->getParsedBody();
40  $queryParams = $request->getQueryParams();
41 
42  // Wizard parameters, coming from FormEngine linking to this wizard.
43  $parameters = $parsedBody['P'] ?? $queryParams['P'] ?? null;
44  $id = $parsedBody['id'] ?? $queryParams['id'] ?? null;
45  $table = $parameters['table'] ?? '';
46  $origRow = BackendUtility::getRecord($table, $parameters['uid']);
47  $tsConfig = BackendUtility::getTCEFORM_TSconfig($table, $origRow ?? ['pid' => $parameters['pid']]);
48 
49  if (str_starts_with($parameters['params']['pid'], '###') && substr($parameters['params']['pid'], -3) === '###') {
50  $keyword = substr($parameters['params']['pid'], 3, -3);
51  if (str_starts_with($keyword, 'PAGE_TSCONFIG_')) {
52  $pid = (int)$tsConfig[$parameters['field']][$keyword];
53  } else {
54  $pid = (int)$tsConfig['_' . $keyword];
55  }
56  } else {
57  $pid = (int)$parameters['params']['pid'];
58  }
59 
60  if ((string)$id !== '') {
61  // If pid is blank
62  $redirectUrl = GeneralUtility::sanitizeLocalUrl($parameters['returnUrl']);
63  } else {
64  // Otherwise, show the list
65  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
66  $normalizedParams = $request->getAttribute('normalizedParams');
67  $requestUri = $normalizedParams->getRequestUri();
68  $urlParameters = [];
69  $urlParameters['id'] = $pid;
70  $urlParameters['table'] = $parameters['params']['table'];
71  $urlParameters['returnUrl'] = !empty($parameters['returnUrl'])
72  ? GeneralUtility::sanitizeLocalUrl($parameters['returnUrl'])
73  : $requestUri;
74  $redirectUrl = (string)$uriBuilder->buildUriFromRoute('web_list', $urlParameters);
75  }
76 
77  return new ‪RedirectResponse($redirectUrl);
78  }
79 }
‪TYPO3\CMS\Backend\Controller\Wizard\ListController\mainAction
‪mainAction(ServerRequestInterface $request)
Definition: ListController.php:37
‪TYPO3\CMS\Backend\Controller\Wizard
Definition: AddController.php:18
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:44
‪TYPO3\CMS\Backend\Controller\Wizard\ListController
Definition: ListController.php:33
‪TYPO3\CMS\Core\Http\RedirectResponse
Definition: RedirectResponse.php:30
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52