Commit d88cef8c authored by Oliver Bartsch's avatar Oliver Bartsch Committed by Christian Kuhn
Browse files

[BUGFIX] Return PSR-7 responses in EXT:form backend controllers

Resolves: #94437
Related: #92784
Releases: master
Change-Id: I759b39fe7b04365293f55a3847a071e7fbfe3308
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/69660


Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Jochen's avatarJochen <rothjochen@gmail.com>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Jochen's avatarJochen <rothjochen@gmail.com>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
parent a03ce8ba
......@@ -17,6 +17,7 @@ declare(strict_types=1);
namespace TYPO3\CMS\Form\Controller;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Backend\Template\Components\ButtonBar;
use TYPO3\CMS\Backend\View\BackendTemplateView;
......@@ -65,10 +66,11 @@ class FormEditorController extends AbstractBackendController
*
* @param string $formPersistenceIdentifier
* @param string $prototypeName
* @return ResponseInterface
* @throws PersistenceManagerException
* @internal
*/
public function indexAction(string $formPersistenceIdentifier, string $prototypeName = null)
public function indexAction(string $formPersistenceIdentifier, string $prototypeName = null): ResponseInterface
{
$this->registerDocHeaderButtons();
$this->view->getModuleTemplate()->setModuleClass($this->request->getPluginName() . '_' . $this->request->getControllerName());
......@@ -143,6 +145,8 @@ class FormEditorController extends AbstractBackendController
);
$this->view->assign('addInlineSettings', $addInlineSettings);
return $this->htmlResponse();
}
/**
......@@ -161,9 +165,10 @@ class FormEditorController extends AbstractBackendController
*
* @param string $formPersistenceIdentifier
* @param FormDefinitionArray $formDefinition
* @return ResponseInterface
* @internal
*/
public function saveFormAction(string $formPersistenceIdentifier, FormDefinitionArray $formDefinition)
public function saveFormAction(string $formPersistenceIdentifier, FormDefinitionArray $formDefinition): ResponseInterface
{
$formDefinition = $formDefinition->getArrayCopy();
......@@ -204,6 +209,13 @@ class FormEditorController extends AbstractBackendController
$this->view->setVariablesToRender([
'response',
]);
$response = $this->responseFactory
->createResponse()
->withAddedHeader('Content-Type', 'application/json; charset=utf-8');
$response->getBody()->write($this->view->render());
return $response;
}
/**
......@@ -213,11 +225,14 @@ class FormEditorController extends AbstractBackendController
* @param FormDefinitionArray $formDefinition
* @param int $pageIndex
* @param string $prototypeName
* @return string
* @return ResponseInterface
* @internal
*/
public function renderFormPageAction(FormDefinitionArray $formDefinition, int $pageIndex, string $prototypeName = null): string
{
public function renderFormPageAction(
FormDefinitionArray $formDefinition,
int $pageIndex,
string $prototypeName = null
): ResponseInterface {
$prototypeName = $prototypeName ?: $formDefinition['prototypeName'] ?? 'standard';
$formDefinition = $formDefinition->getArrayCopy();
......@@ -228,7 +243,7 @@ class FormEditorController extends AbstractBackendController
$form->setCurrentSiteLanguage($this->buildFakeSiteLanguage(0, 0));
$form->overrideCurrentPage($pageIndex);
return $form->render();
return $this->htmlResponse($form->render());
}
/**
......
......@@ -17,6 +17,7 @@ declare(strict_types=1);
namespace TYPO3\CMS\Form\Controller;
use Psr\Http\Message\ResponseInterface;
use Symfony\Component\Yaml\Yaml;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Backend\Template\Components\ButtonBar;
......@@ -75,9 +76,10 @@ class FormManagerController extends AbstractBackendController
* Displays the Form Manager
*
* @param int $page
* @return ResponseInterface
* @internal
*/
public function indexAction(int $page = 1)
public function indexAction(int $page = 1): ResponseInterface
{
$this->registerDocHeaderButtons();
$this->view->getModuleTemplate()->setModuleClass($this->request->getPluginName() . '_' . $this->request->getControllerName());
......@@ -103,6 +105,8 @@ class FormManagerController extends AbstractBackendController
if (!empty($this->formSettings['formManager']['javaScriptTranslationFile'])) {
$this->getPageRenderer()->addInlineLanguageLabelFile($this->formSettings['formManager']['javaScriptTranslationFile']);
}
return $this->htmlResponse();
}
/**
......@@ -123,11 +127,12 @@ class FormManagerController extends AbstractBackendController
* @param string $templatePath
* @param string $prototypeName
* @param string $savePath
* @return ResponseInterface
* @throws FormException
* @throws PersistenceManagerException
* @internal
*/
public function createAction(string $formName, string $templatePath, string $prototypeName, string $savePath)
public function createAction(string $formName, string $templatePath, string $prototypeName, string $savePath): ResponseInterface
{
if (!$this->formPersistenceManager->isAllowedPersistencePath($savePath)) {
throw new PersistenceManagerException(sprintf('Save to path "%s" is not allowed', $savePath), 1614500657);
......@@ -179,6 +184,13 @@ class FormManagerController extends AbstractBackendController
$this->view->setVariablesToRender([
'response',
]);
$response = $this->responseFactory
->createResponse()
->withAddedHeader('Content-Type', 'application/json; charset=utf-8');
$response->getBody()->write($this->view->render());
return $response;
}
/**
......@@ -198,10 +210,11 @@ class FormManagerController extends AbstractBackendController
* @param string $formName
* @param string $formPersistenceIdentifier persistence identifier of the form to duplicate
* @param string $savePath
* @return ResponseInterface
* @throws PersistenceManagerException
* @internal
*/
public function duplicateAction(string $formName, string $formPersistenceIdentifier, string $savePath)
public function duplicateAction(string $formName, string $formPersistenceIdentifier, string $savePath): ResponseInterface
{
if (!$this->formPersistenceManager->isAllowedPersistencePath($savePath)) {
throw new PersistenceManagerException(sprintf('Save to path "%s" is not allowed', $savePath), 1614500658);
......@@ -247,6 +260,13 @@ class FormManagerController extends AbstractBackendController
$this->view->setVariablesToRender([
'response',
]);
$response = $this->responseFactory
->createResponse()
->withAddedHeader('Content-Type', 'application/json; charset=utf-8');
$response->getBody()->write($this->view->render());
return $response;
}
/**
......@@ -264,10 +284,11 @@ class FormManagerController extends AbstractBackendController
* Show references to this persistence identifier
*
* @param string $formPersistenceIdentifier persistence identifier of the form to duplicate
* @return ResponseInterface
* @throws PersistenceManagerException
* @internal
*/
public function referencesAction(string $formPersistenceIdentifier)
public function referencesAction(string $formPersistenceIdentifier): ResponseInterface
{
if (!$this->formPersistenceManager->isAllowedPersistencePath($formPersistenceIdentifier)) {
throw new PersistenceManagerException(sprintf('Read from "%s" is not allowed', $formPersistenceIdentifier), 1614500660);
......@@ -281,6 +302,13 @@ class FormManagerController extends AbstractBackendController
'references',
'formPersistenceIdentifier'
]);
$response = $this->responseFactory
->createResponse()
->withAddedHeader('Content-Type', 'application/json; charset=utf-8');
$response->getBody()->write($this->view->render());
return $response;
}
/**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment