‪TYPO3CMS  ‪main
RedirectFinisher.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 
23 
30 {
34  protected ‪$defaultOptions = [
35  'pageUid' => 1,
36  'additionalParameters' => '',
37  'statusCode' => 303,
38  'fragment' => '',
39  ];
40 
45  protected function ‪executeInternal()
46  {
47  $pageUid = $this->‪parseOption('pageUid');
48  $pageUid = (int)str_replace('pages_', '', (string)$pageUid);
49  $additionalParameters = $this->‪parseOption('additionalParameters');
50  $additionalParameters = is_string($additionalParameters) ? $additionalParameters : '';
51  $additionalParameters = '&' . ltrim($additionalParameters, '&');
52  ‪$statusCode = (int)$this->‪parseOption('statusCode');
53  $fragment = (string)$this->‪parseOption('fragment');
54 
55  $this->finisherContext->cancel();
56  $this->‪redirect($pageUid, $additionalParameters, $fragment, ‪$statusCode);
57  }
58 
72  protected function ‪redirect(int $pageUid, string $additionalParameters, string $fragment, int ‪$statusCode)
73  {
74  $typolinkConfiguration = [
75  'parameter' => $pageUid,
76  'additionalParams' => $additionalParameters,
77  'section' => $fragment,
78  ];
79  $redirectUri = $this->‪getTypoScriptFrontendController()->cObj->createUrl($typolinkConfiguration);
80  $this->‪redirectToUri($redirectUri, ‪$statusCode);
81  }
82 
92  protected function ‪redirectToUri(string $uri, int ‪$statusCode = 303)
93  {
94  $uri = $this->‪addBaseUriIfNecessary($uri);
95  $response = new ‪RedirectResponse($uri, ‪$statusCode);
96  // End processing and dispatching by throwing a PropagateResponseException with our response.
97  // @todo: Should be changed to *return* a response instead, but this requires the ContentObjectRender
98  // @todo: to deal with responses instead of strings, if the form is used in a fluid template rendered by the
99  // @todo: FluidTemplateContentObject and the extbase bootstrap isn't used.
100  throw new ‪PropagateResponseException($response, 1477070964);
101  }
102 
108  protected function ‪addBaseUriIfNecessary(string $uri): string
109  {
110  return GeneralUtility::locationHeaderUrl($uri);
111  }
112 }
‪TYPO3\CMS\Form\Domain\Finishers\RedirectFinisher\addBaseUriIfNecessary
‪addBaseUriIfNecessary(string $uri)
Definition: RedirectFinisher.php:107
‪TYPO3\CMS\Form\Domain\Finishers\RedirectFinisher\redirect
‪redirect(int $pageUid, string $additionalParameters, string $fragment, int $statusCode)
Definition: RedirectFinisher.php:71
‪TYPO3\CMS\Form\Domain\Finishers
Definition: AbstractFinisher.php:22
‪TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher\parseOption
‪string array int null parseOption(string $optionName)
Definition: AbstractFinisher.php:139
‪TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher\getTypoScriptFrontendController
‪getTypoScriptFrontendController()
Definition: AbstractFinisher.php:360
‪TYPO3\CMS\Redirects\Message\$statusCode
‪identifier readonly UriInterface readonly int $statusCode
Definition: RedirectWasHitMessage.php:34
‪TYPO3\CMS\Form\Domain\Finishers\RedirectFinisher\redirectToUri
‪redirectToUri(string $uri, int $statusCode=303)
Definition: RedirectFinisher.php:91
‪TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher
Definition: AbstractFinisher.php:41
‪TYPO3\CMS\Form\Domain\Finishers\RedirectFinisher\executeInternal
‪executeInternal()
Definition: RedirectFinisher.php:44
‪TYPO3\CMS\Core\Http\PropagateResponseException
Definition: PropagateResponseException.php:47
‪TYPO3\CMS\Core\Http\RedirectResponse
Definition: RedirectResponse.php:30
‪TYPO3\CMS\Form\Domain\Finishers\RedirectFinisher\$defaultOptions
‪array $defaultOptions
Definition: RedirectFinisher.php:33
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Form\Domain\Finishers\RedirectFinisher
Definition: RedirectFinisher.php:30