Skip to content

Commit

Permalink
[TASK] Drop remaining HttpUtility and getIndpEnv() in Wizard/AddContr…
Browse files Browse the repository at this point in the history
…oller

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 <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
  • Loading branch information
mbrodala authored and lolli42 committed Mar 17, 2018
1 parent 3bf44e5 commit a7b1805
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 18 deletions.
50 changes: 32 additions & 18 deletions typo3/sysext/backend/Classes/Controller/Wizard/AddController.php
Expand Up @@ -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;
Expand Down Expand Up @@ -119,8 +120,7 @@ public function __construct()
*/
public function mainAction(ServerRequestInterface $request): ResponseInterface
{
$this->processRequest();
return new HtmlResponse('');
return $this->processRequest($request);
}

/**
Expand All @@ -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]);
}

/**
Expand Down Expand Up @@ -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...
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
Expand Up @@ -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.


Expand Down

0 comments on commit a7b1805

Please sign in to comment.