‪TYPO3CMS  11.5
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 
24 
31 {
35  protected ‪$defaultOptions = [
36  'pageUid' => 1,
37  'additionalParameters' => '',
38  'statusCode' => 303,
39  ];
40 
44  protected ‪$request;
45 
49  protected ‪$uriBuilder;
50 
55  protected function ‪executeInternal()
56  {
57  $formRuntime = $this->finisherContext->getFormRuntime();
58  $this->request = $formRuntime->getRequest();
59  $this->uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
60  $this->uriBuilder->setRequest($this->request);
61 
62  $pageUid = $this->‪parseOption('pageUid');
63  $pageUid = (int)str_replace('pages_', '', (string)$pageUid);
64  $additionalParameters = $this->‪parseOption('additionalParameters');
65  $additionalParameters = is_string($additionalParameters) ? $additionalParameters : '';
66  $additionalParameters = '&' . ltrim($additionalParameters, '&');
67  $statusCode = (int)$this->‪parseOption('statusCode');
68 
69  $this->finisherContext->cancel();
70  $this->‪redirect($pageUid, $additionalParameters, $statusCode);
71  }
72 
86  protected function ‪redirect(int $pageUid = 1, string $additionalParameters = '', int $statusCode = 303)
87  {
88  $typolinkConfiguration = [
89  'parameter' => $pageUid,
90  'additionalParams' => $additionalParameters,
91  ];
92  $redirectUri = $this->‪getTypoScriptFrontendController()->cObj->typoLink_URL($typolinkConfiguration);
93  $this->‪redirectToUri($redirectUri, $statusCode);
94  }
95 
105  protected function ‪redirectToUri(string $uri, int $statusCode = 303)
106  {
107  $uri = $this->‪addBaseUriIfNecessary($uri);
108  $response = new ‪RedirectResponse($uri, $statusCode);
109  // End processing and dispatching by throwing a PropagateResponseException with our response.
110  // @todo: Should be changed to *return* a response instead, but this requires the ContentObjectRender
111  // @todo: to deal with responses instead of strings, if the form is used in a fluid template rendered by the
112  // @todo: FluidTemplateContentObject and the extbase bootstrap isn't used.
113  throw new ‪PropagateResponseException($response, 1477070964);
114  }
115 
122  protected function ‪addBaseUriIfNecessary(string $uri): string
123  {
124  return GeneralUtility::locationHeaderUrl((string)$uri);
125  }
126 }
‪TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder
Definition: UriBuilder.php:41
‪TYPO3\CMS\Form\Domain\Finishers\RedirectFinisher\$request
‪TYPO3 CMS Extbase Mvc Request $request
Definition: RedirectFinisher.php:42
‪TYPO3\CMS\Form\Domain\Finishers
Definition: AbstractFinisher.php:22
‪TYPO3\CMS\Form\Domain\Finishers\RedirectFinisher\redirect
‪redirect(int $pageUid=1, string $additionalParameters='', int $statusCode=303)
Definition: RedirectFinisher.php:83
‪TYPO3\CMS\Form\Domain\Finishers\RedirectFinisher\$uriBuilder
‪TYPO3 CMS Extbase Mvc Web Routing UriBuilder $uriBuilder
Definition: RedirectFinisher.php:46
‪TYPO3\CMS\Form\Domain\Finishers\RedirectFinisher\redirectToUri
‪redirectToUri(string $uri, int $statusCode=303)
Definition: RedirectFinisher.php:102
‪TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher
Definition: AbstractFinisher.php:42
‪TYPO3\CMS\Form\Domain\Finishers\RedirectFinisher\executeInternal
‪executeInternal()
Definition: RedirectFinisher.php:52
‪TYPO3\CMS\Form\Domain\Finishers\RedirectFinisher\addBaseUriIfNecessary
‪string addBaseUriIfNecessary(string $uri)
Definition: RedirectFinisher.php:119
‪TYPO3\CMS\Core\Http\PropagateResponseException
Definition: PropagateResponseException.php:47
‪TYPO3\CMS\Core\Http\RedirectResponse
Definition: RedirectResponse.php:28
‪TYPO3\CMS\Form\Domain\Finishers\RedirectFinisher\$defaultOptions
‪array $defaultOptions
Definition: RedirectFinisher.php:34
‪TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher\parseOption
‪string array null parseOption(string $optionName)
Definition: AbstractFinisher.php:172
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Form\Domain\Finishers\RedirectFinisher
Definition: RedirectFinisher.php:31
‪TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher\getTypoScriptFrontendController
‪TypoScriptFrontendController getTypoScriptFrontendController()
Definition: AbstractFinisher.php:402