From a7b18059d1f40e4199e29024dc8a6522fd1af1a5 Mon Sep 17 00:00:00 2001 From: Mathias Brodala Date: Sat, 17 Mar 2018 09:40:27 +0100 Subject: [PATCH] [TASK] Drop remaining HttpUtility and getIndpEnv() in Wizard/AddController Also simplify processing since we always perform a redirect at some point. Change-Id: Ib1adbf4226d439ab879d42a448aa1a77ef398b75 Resolves: #84392 Releases: master Reviewed-on: https://review.typo3.org/56272 Reviewed-by: Anja Leichsenring Tested-by: Anja Leichsenring Tested-by: TYPO3com Reviewed-by: Christian Kuhn Tested-by: Christian Kuhn --- .../Controller/Wizard/AddController.php | 50 ++++++++++++------- ...tedMethodsAndPropertiesInAddController.rst | 4 ++ 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/typo3/sysext/backend/Classes/Controller/Wizard/AddController.php b/typo3/sysext/backend/Classes/Controller/Wizard/AddController.php index 812dd832ef64..369780672f3d 100644 --- a/typo3/sysext/backend/Classes/Controller/Wizard/AddController.php +++ b/typo3/sysext/backend/Classes/Controller/Wizard/AddController.php @@ -19,11 +19,12 @@ use Psr\Http\Message\ServerRequestInterface; use TYPO3\CMS\Backend\Form\FormDataCompiler; use TYPO3\CMS\Backend\Form\FormDataGroup\TcaDatabaseRecord; +use TYPO3\CMS\Backend\Routing\UriBuilder; use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Core\Compatibility\PublicPropertyDeprecationTrait; use TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools; use TYPO3\CMS\Core\DataHandling\DataHandler; -use TYPO3\CMS\Core\Http\HtmlResponse; +use TYPO3\CMS\Core\Http\RedirectResponse; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\HttpUtility; use TYPO3\CMS\Core\Utility\MathUtility; @@ -119,8 +120,7 @@ public function __construct() */ public function mainAction(ServerRequestInterface $request): ResponseInterface { - $this->processRequest(); - return new HtmlResponse(''); + return $this->processRequest($request); } /** @@ -132,7 +132,9 @@ public function mainAction(ServerRequestInterface $request): ResponseInterface public function main() { trigger_error('Method main() will be replaced by protected method processRequest() in v10. Do not call from other extension', E_USER_DEPRECATED); - $this->processRequest(); + + $response = $this->processRequest($GLOBALS['TYPO3_REQUEST']); + HttpUtility::redirect($response->getHeaders()['location'][0]); } /** @@ -168,7 +170,8 @@ protected function init(ServerRequestInterface $request): void } // Return if new record as parent (not possibly/allowed) if ($this->pid === '') { - HttpUtility::redirect(GeneralUtility::sanitizeLocalUrl($this->P['returnUrl'])); + // HTTP Redirect is performed by processRequest() + return; } // Else proceed: // If a new id has returned from a newly created record... @@ -200,9 +203,17 @@ protected function init(ServerRequestInterface $request): void /** * Main function * Will issue a location-header, redirecting either BACK or to a new FormEngine instance... + * + * @param ServerRequestInterface $request + * @return ResponseInterface */ - protected function processRequest(): void + protected function processRequest(ServerRequestInterface $request): ResponseInterface { + // Return if new record as parent (not possibly/allowed) + if ($this->pid === '') { + return new RedirectResponse(GeneralUtility::sanitizeLocalUrl($this->P['returnUrl'])); + } + if ($this->returnEditConf) { if ($this->processDataFlag) { // Because OnTheFly can't handle MM relations with intermediate tables we use TcaDatabaseRecord here @@ -304,18 +315,21 @@ protected function processRequest(): void } } // Return to the parent FormEngine record editing session: - HttpUtility::redirect(GeneralUtility::sanitizeLocalUrl($this->P['returnUrl'])); - } else { - // Redirecting to FormEngine with instructions to create a new record - // AND when closing to return back with information about that records ID etc. - /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */ - $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class); - $redirectUrl = (string)$uriBuilder->buildUriFromRoute('record_edit', [ - 'returnEditConf' => 1, - 'edit[' . $this->P['params']['table'] . '][' . $this->pid . ']' => 'new', - 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI') - ]); - HttpUtility::redirect($redirectUrl); + return new RedirectResponse(GeneralUtility::sanitizeLocalUrl($this->P['returnUrl'])); } + + // Redirecting to FormEngine with instructions to create a new record + // AND when closing to return back with information about that records ID etc. + /** @var \TYPO3\CMS\Core\Http\NormalizedParams */ + $normalizedParams = $request->getAttribute('normalizedParams'); + /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */ + $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); + $redirectUrl = (string)$uriBuilder->buildUriFromRoute('record_edit', [ + 'returnEditConf' => 1, + 'edit[' . $this->P['params']['table'] . '][' . $this->pid . ']' => 'new', + 'returnUrl' => $normalizedParams->getRequestUri(), + ]); + + return new RedirectResponse($redirectUrl); } } diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-84321-ProtectedMethodsAndPropertiesInAddController.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-84321-ProtectedMethodsAndPropertiesInAddController.rst index 1a0d1cb78b2e..58eb96214fd8 100644 --- a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-84321-ProtectedMethodsAndPropertiesInAddController.rst +++ b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-84321-ProtectedMethodsAndPropertiesInAddController.rst @@ -29,6 +29,10 @@ removed or set to protected in v10 and throw deprecation warnings if used from a * [not scanned] :php:`init()` * [not scanned] :php:`main()` +Due to refactoring the :php:`init()` method does not perform a redirect anymore in case no ``pid`` +was set by GET params. This redirect has been moved and will be performed for legacy code by the +deprecated :php:`main()` method now. + Additionally :php:`$GLOBALS['SOBE']` is not set by the :php:`AddController` constructor anymore.