Skip to content

Commit

Permalink
[BUGFIX] Finishers with output must return the output
Browse files Browse the repository at this point in the history
Since #83822 EXT:form makes usage of the controller context
response object which has impacts to the finisher logic which was not
treated by #83822.
Now, finishers with output can return this as string instead of setting
this directly into the response (which results in a double output).

Resolves: #84495
Releases: master, 8.7
Change-Id: Ib5accba1004b857b5447ae26dff8a689acfa6579
Reviewed-on: https://review.typo3.org/56665
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
  • Loading branch information
waldhacker1 authored and neufeind committed Apr 15, 2018
1 parent f5d8b67 commit 6176a2a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
Expand Up @@ -116,19 +116,21 @@ public function setOption(string $optionName, $optionValue)
* Executes the finisher
*
* @param FinisherContext $finisherContext The Finisher context that contains the current Form Runtime and Response
* @return string|null
* @api
*/
final public function execute(FinisherContext $finisherContext)
{
$this->finisherContext = $finisherContext;
$this->executeInternal();
return $this->executeInternal();
}

/**
* This method is called in the concrete finisher whenever self::execute() is called.
*
* Override and fill with your own implementation!
*
* @return string|null
* @api
*/
abstract protected function executeInternal();
Expand Down
Expand Up @@ -51,14 +51,15 @@ class ConfirmationFinisher extends AbstractFinisher

/**
* Executes this finisher
*
* @see AbstractFinisher::execute()
* @return string
*
* @throws FinisherException
*/
protected function executeInternal()
{
$formRuntime = $this->finisherContext->getFormRuntime();
$message = $this->parseOption('message');
$formRuntime->getResponse()->setContent($message);
return $message;
}
}
Expand Up @@ -30,6 +30,7 @@ interface FinisherInterface
* Executes the finisher
*
* @param FinisherContext $finisherContext The Finisher context that contains the current Form Runtime and Response
* @return string|null
* @api
*/
public function execute(FinisherContext $finisherContext);
Expand Down
16 changes: 12 additions & 4 deletions typo3/sysext/form/Classes/Domain/Runtime/FormRuntime.php
Expand Up @@ -540,8 +540,7 @@ public function overrideCurrentPage(int $pageIndex)
public function render()
{
if ($this->isAfterLastPage()) {
$this->invokeFinishers();
return $this->response->getContent();
return $this->invokeFinishers();
}

$this->formState->setLastDisplayedPageIndex($this->currentPage->getIndex());
Expand All @@ -564,20 +563,29 @@ public function render()

/**
* Executes all finishers of this form
*
* @return string
*/
protected function invokeFinishers()
protected function invokeFinishers(): string
{
$finisherContext = $this->objectManager->get(
FinisherContext::class,
$this,
$this->getControllerContext()
);

$output = '';
foreach ($this->formDefinition->getFinishers() as $finisher) {
$finisher->execute($finisherContext);
$finisherOutput = $finisher->execute($finisherContext);
if (is_string($finisherOutput) && !empty($finisherOutput)) {
$output .= $finisherOutput;
}
if ($finisherContext->isCancelled()) {
break;
}
}

return $output;
}

/**
Expand Down

0 comments on commit 6176a2a

Please sign in to comment.