‪TYPO3CMS  ‪main
ReturnUrl.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\ServerRequestInterface;
21 
34 {
35  public function ‪__construct(private readonly ‪UriBuilder $uriBuilder) {}
36 
37  public function ‪addData(array $result): array
38  {
39  if ($result['returnUrl'] !== null) {
40  return $result;
41  }
43  $request = $result['request'];
44  $routeIdentifier = $request->getAttribute('route')?->getOption('_identifier');
45  if ($routeIdentifier === null) {
46  // Route could not be found. This usually should not happen in any
47  // backend context, but is sanitized here nevertheless. returnUrl
48  // will be kept as null in this case, which may or may not trigger
49  // subsequent issues.
50  return $result;
51  }
52  $queryParams = $request->getQueryParams();
53  $relevantQueryParams = [];
54  foreach ($queryParams as $queryKey => $queryValue) {
55  if (in_array($queryKey, ['token', 'returnUrl'], true)) {
56  continue;
57  }
58  $relevantQueryParams[$queryKey] = $queryValue;
59  }
60  $result['returnUrl'] = (string)$this->uriBuilder->buildUriFromRoute($routeIdentifier, $relevantQueryParams);
61  return $result;
62  }
63 }
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:44
‪TYPO3\CMS\Backend\Form\FormDataProvider\ReturnUrl
Definition: ReturnUrl.php:34
‪TYPO3\CMS\Backend\Form\FormDataProvider
Definition: AbstractDatabaseRecordProvider.php:16
‪TYPO3\CMS\Backend\Form\FormDataProviderInterface
Definition: FormDataProviderInterface.php:23
‪TYPO3\CMS\Backend\Form\FormDataProvider\ReturnUrl\__construct
‪__construct(private readonly UriBuilder $uriBuilder)
Definition: ReturnUrl.php:35
‪TYPO3\CMS\Backend\Form\FormDataProvider\ReturnUrl\addData
‪addData(array $result)
Definition: ReturnUrl.php:37