‪TYPO3CMS  10.4
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 {
31 
35  protected ‪$defaultOptions = [
36  'pageUid' => 1,
37  'additionalParameters' => '',
38  'delay' => 0,
39  'statusCode' => 303,
40  ];
41 
45  protected ‪$request;
46 
50  protected ‪$response;
51 
55  protected ‪$uriBuilder;
56 
61  protected function ‪executeInternal()
62  {
63  $formRuntime = $this->finisherContext->getFormRuntime();
64  $this->request = $formRuntime->getRequest();
65  $this->response = $formRuntime->getResponse();
66  $this->uriBuilder = $this->objectManager->get(UriBuilder::class);
67  $this->uriBuilder->setRequest($this->request);
68 
69  $pageUid = $this->‪parseOption('pageUid');
70  $pageUid = (int)str_replace('pages_', '', (string)$pageUid);
71  $additionalParameters = $this->‪parseOption('additionalParameters');
72  $additionalParameters = is_string($additionalParameters) ? $additionalParameters : '';
73  $additionalParameters = '&' . ltrim($additionalParameters, '&');
74  $delay = (int)$this->‪parseOption('delay');
75  $statusCode = (int)$this->‪parseOption('statusCode');
76 
77  $this->finisherContext->cancel();
78  $this->‪redirect($pageUid, $additionalParameters, $delay, $statusCode);
79  }
80 
95  protected function ‪redirect(int $pageUid = 1, string $additionalParameters = '', int $delay = 0, int $statusCode = 303)
96  {
97  $typolinkConfiguration = [
98  'parameter' => $pageUid,
99  'additionalParams' => $additionalParameters,
100  ];
101  $redirectUri = $this->‪getTypoScriptFrontendController()->cObj->typoLink_URL($typolinkConfiguration);
102  $this->‪redirectToUri($redirectUri, $delay, $statusCode);
103  }
104 
115  protected function ‪redirectToUri(string $uri, int $delay = 0, int $statusCode = 303)
116  {
117  $uri = $this->‪addBaseUriIfNecessary($uri);
118  $escapedUri = htmlentities($uri, ENT_QUOTES, 'utf-8');
119 
120  $this->response->setContent('<html><head><meta http-equiv="refresh" content="' . (int)$delay . ';url=' . $escapedUri . '"/></head></html>');
121  $this->response->setStatus($statusCode);
122  $this->response->setHeader('Location', (string)$uri);
123  throw new StopActionException('redirectToUri', 1477070964);
124  }
125 
132  protected function ‪addBaseUriIfNecessary(string $uri): string
133  {
134  return GeneralUtility::locationHeaderUrl((string)$uri);
135  }
136 }
‪TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
Definition: StopActionException.php:31
‪TYPO3\CMS\Form\Domain\Finishers\RedirectFinisher\redirect
‪redirect(int $pageUid=1, string $additionalParameters='', int $delay=0, int $statusCode=303)
Definition: RedirectFinisher.php:91
‪TYPO3\CMS\Form\Domain\Finishers\RedirectFinisher\$response
‪TYPO3 CMS Extbase Mvc Web Response $response
Definition: RedirectFinisher.php:47
‪TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder
Definition: UriBuilder.php:39
‪TYPO3\CMS\Form\Domain\Finishers
Definition: AbstractFinisher.php:22
‪TYPO3\CMS\Form\Domain\Finishers\RedirectFinisher\$uriBuilder
‪TYPO3 CMS Extbase Mvc Web Routing UriBuilder $uriBuilder
Definition: RedirectFinisher.php:51
‪TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher
Definition: AbstractFinisher.php:41
‪TYPO3\CMS\Form\Domain\Finishers\RedirectFinisher\executeInternal
‪executeInternal()
Definition: RedirectFinisher.php:57
‪TYPO3\CMS\Form\Domain\Finishers\RedirectFinisher\$request
‪TYPO3 CMS Extbase Mvc Web Request $request
Definition: RedirectFinisher.php:43
‪TYPO3\CMS\Form\Domain\Finishers\RedirectFinisher\addBaseUriIfNecessary
‪string addBaseUriIfNecessary(string $uri)
Definition: RedirectFinisher.php:128
‪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:161
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Form\Domain\Finishers\RedirectFinisher\redirectToUri
‪redirectToUri(string $uri, int $delay=0, int $statusCode=303)
Definition: RedirectFinisher.php:111
‪TYPO3\CMS\Form\Domain\Finishers\RedirectFinisher
Definition: RedirectFinisher.php:30
‪TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher\getTypoScriptFrontendController
‪TypoScriptFrontendController getTypoScriptFrontendController()
Definition: AbstractFinisher.php:391