Commit d7e560a1 authored by Benni Mack's avatar Benni Mack Committed by Susanne Moog
Browse files

[TASK] Use JsonResponse for all Backend AJAX calls

The new JsonResponse object should be used throughout the
TYPO3 Backend in order to properly call json_encode() with
the right flags automatically, making the code inside
the controllers simpler.

Resolves: #83267
Releases: master
Change-Id: Ie03fb1414a965a61632897f0e25645a67f3225a5
Reviewed-on: https://review.typo3.org/54995


Tested-by: default avatarTYPO3com <no-reply@typo3.com>
Reviewed-by: default avatarStefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: default avatarStefan Neufeind <typo3.neufeind@speedpartner.de>
Reviewed-by: Susanne Moog's avatarSusanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog's avatarSusanne Moog <susanne.moog@typo3.org>
parent e681cfaa
......@@ -23,6 +23,7 @@ use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryHelper;
use TYPO3\CMS\Core\Http\JsonResponse;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Page\PageRenderer;
......@@ -481,10 +482,9 @@ class ShortcutToolbarItem implements ToolbarItemInterface
* Deletes a shortcut through an AJAX call
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @return ResponseInterface
*/
public function removeShortcutAction(ServerRequestInterface $request, ResponseInterface $response)
public function removeShortcutAction(ServerRequestInterface $request): ResponseInterface
{
$parsedBody = $request->getParsedBody();
$queryParams = $request->getQueryParams();
......@@ -507,8 +507,7 @@ class ShortcutToolbarItem implements ToolbarItemInterface
$success = true;
}
}
$response->getBody()->write(json_encode(['success' => $success]));
return $response;
return GeneralUtility::makeInstance(JsonResponse::class, ['success' => $success]);
}
/**
......
......@@ -17,6 +17,8 @@ namespace TYPO3\CMS\Backend\Controller;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Http\JsonResponse;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* This is the ajax handler for backend login after timeout.
......@@ -31,10 +33,9 @@ class AjaxLoginController
* If it was unsuccessful, we display that and show the login box again.
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @return ResponseInterface
*/
public function loginAction(ServerRequestInterface $request, ResponseInterface $response)
public function loginAction(ServerRequestInterface $request): ResponseInterface
{
if ($this->isAuthorizedBackendSession()) {
$result = ['success' => true];
......@@ -46,58 +47,49 @@ class AjaxLoginController
} else {
$result = ['success' => false];
}
$response->getBody()->write(json_encode(['login' => $result]));
return $response;
return GeneralUtility::makeInstance(JsonResponse::class, ['login' => $result]);
}
/**
* Logs out the current BE user
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @return ResponseInterface
*/
public function logoutAction(ServerRequestInterface $request, ResponseInterface $response)
public function logoutAction(ServerRequestInterface $request): ResponseInterface
{
$backendUser = $this->getBackendUser();
$backendUser->logoff();
$response->getBody()->write(json_encode([
return GeneralUtility::makeInstance(JsonResponse::class, [
'logout' => [
'success' => !isset($backendUser->user['uid'])
]
]));
return $response;
]);
}
/**
* Refreshes the login without needing login information. We just refresh the session.
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @return ResponseInterface
*/
public function refreshAction(ServerRequestInterface $request, ResponseInterface $response)
public function refreshAction(ServerRequestInterface $request): ResponseInterface
{
$this->getBackendUser()->checkAuthentication();
$response->getBody()->write(json_encode([
return GeneralUtility::makeInstance(JsonResponse::class, [
'refresh' => [
'success' => true
]
]));
return $response;
]);
}
/**
* Checks if the user session is expired yet
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @return ResponseInterface
*/
public function isTimedOutAction(ServerRequestInterface $request, ResponseInterface $response)
public function isTimedOutAction(ServerRequestInterface $request): ResponseInterface
{
$session = [
'timed_out' => false,
......@@ -117,8 +109,7 @@ class AjaxLoginController
// 120 is somewhat arbitrary to allow for a little room during the countdown and load times, etc.
$session['will_time_out'] = $GLOBALS['EXEC_TIME'] >= $ses_tstamp + $timeout - 120;
}
$response->getBody()->write(json_encode(['login' => $session]));
return $response;
return GeneralUtility::makeInstance(JsonResponse::class, ['login' => $session]);
}
/**
......
......@@ -25,6 +25,7 @@ use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Http\JsonResponse;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Type\Bitmask\Permission;
......@@ -585,28 +586,22 @@ class BackendController
* Returns the Module menu for the AJAX request
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @return ResponseInterface
*/
public function getModuleMenu(ServerRequestInterface $request, ResponseInterface $response)
public function getModuleMenu(ServerRequestInterface $request): ResponseInterface
{
$content = $this->generateModuleMenu();
$response->getBody()->write(json_encode(['menu' => $content]));
return $response;
return GeneralUtility::makeInstance(JsonResponse::class, ['menu' => $this->generateModuleMenu()]);
}
/**
* Returns the toolbar for the AJAX request
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @return ResponseInterface
*/
public function getTopbar(ServerRequestInterface $request, ResponseInterface $response)
public function getTopbar(ServerRequestInterface $request): ResponseInterface
{
$response->getBody()->write(json_encode(['topbar' => $this->renderTopbar()]));
return $response;
return GeneralUtility::makeInstance(JsonResponse::class, ['topbar' => $this->renderTopbar()]);
}
/**
......
......@@ -17,6 +17,7 @@ namespace TYPO3\CMS\Backend\Controller;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Http\JsonResponse;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
......@@ -33,16 +34,16 @@ class ContextHelpAjaxController
* @param ResponseInterface $response
* @return ResponseInterface
*/
public function getHelpAction(ServerRequestInterface $request, ResponseInterface $response)
public function getHelpAction(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
{
$params = isset($request->getParsedBody()['params']) ? $request->getParsedBody()['params'] : $request->getQueryParams()['params'];
if ($params['action'] === 'getContextHelp') {
$result = $this->getContextHelp($params['table'], $params['field']);
$response->getBody()->write(json_encode([
return GeneralUtility::makeInstance(JsonResponse::class, [
'title' => $result['title'],
'content' => $result['description'],
'link' => $result['moreInfo']
]));
]);
}
return $response;
}
......
......@@ -19,6 +19,7 @@ use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Clipboard\Clipboard;
use TYPO3\CMS\Backend\ContextMenu\ContextMenu;
use TYPO3\CMS\Core\Http\JsonResponse;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
......@@ -39,10 +40,9 @@ class ContextMenuController
* Renders a context menu
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @return ResponseInterface
*/
public function getContextMenuAction(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
public function getContextMenuAction(ServerRequestInterface $request): ResponseInterface
{
$contextMenu = GeneralUtility::makeInstance(ContextMenu::class);
......@@ -52,16 +52,14 @@ class ContextMenuController
if (!is_array($items)) {
$items = [];
}
$response->getBody()->write(json_encode($items));
return $response;
return GeneralUtility::makeInstance(JsonResponse::class)->setPayload($items);
}
/**
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @return ResponseInterface
*/
public function clipboardAction(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
public function clipboardAction(ServerRequestInterface $request): ResponseInterface
{
/** @var Clipboard $clipboard */
$clipboard = GeneralUtility::makeInstance(Clipboard::class);
......@@ -72,8 +70,7 @@ class ContextMenuController
$clipboard->cleanCurrent();
$clipboard->endClipboard();
$response->getBody()->write(json_encode([]));
return $response;
return GeneralUtility::makeInstance(JsonResponse::class)->setPayload([]);
}
/**
......
......@@ -17,6 +17,7 @@ namespace TYPO3\CMS\Backend\Controller\File;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Http\JsonResponse;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Resource\DuplicationBehavior;
......@@ -232,7 +233,7 @@ class FileController
}
}
}
$response->getBody()->write(json_encode($flatResult));
return GeneralUtility::makeInstance(JsonResponse::class)->setPayload($flatResult);
}
return $response;
}
......@@ -241,10 +242,9 @@ class FileController
* Ajax entry point to check if a file exists in a folder
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @return ResponseInterface
*/
public function fileExistsInFolderAction(ServerRequestInterface $request, ResponseInterface $response)
public function fileExistsInFolderAction(ServerRequestInterface $request)
{
$fileName = isset($request->getParsedBody()['fileName']) ? $request->getParsedBody()['fileName'] : $request->getQueryParams()['fileName'];
$fileTarget = isset($request->getParsedBody()['fileTarget']) ? $request->getParsedBody()['fileTarget'] : $request->getQueryParams()['fileTarget'];
......@@ -259,8 +259,7 @@ class FileController
if ($fileTargetObject->hasFile($processedFileName)) {
$result = $this->flattenResultDataValue($fileTargetObject->getStorage()->getFileInFolder($processedFileName, $fileTargetObject));
}
$response->getBody()->write(json_encode($result));
return $response;
return GeneralUtility::makeInstance(JsonResponse::class)->setPayload([$result]);
}
/**
......
......@@ -20,6 +20,7 @@ use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Backend\Template\Components\ButtonBar;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Backend\Tree\View\ElementBrowserFolderTreeView;
use TYPO3\CMS\Core\Http\JsonResponse;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
......@@ -228,17 +229,14 @@ class FileSystemNavigationFrameController
* @param ResponseInterface $response
* @return ResponseInterface
*/
public function ajaxExpandCollapse(ServerRequestInterface $request, ResponseInterface $response)
public function ajaxExpandCollapse(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
{
$this->init();
$tree = $this->foldertree->getBrowsableTree();
if ($this->foldertree->getAjaxStatus() === false) {
$response = $response->withStatus(500);
} else {
$response->getBody()->write(json_encode($tree));
return $response->withStatus(500);
}
return $response;
return GeneralUtility::makeInstance(JsonResponse::class, $tree);
}
/**
......
......@@ -17,6 +17,7 @@ namespace TYPO3\CMS\Backend\Controller;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Http\JsonResponse;
use TYPO3\CMS\Core\Messaging\FlashMessageService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
......@@ -29,10 +30,9 @@ class FlashMessageController
* Renders the FlashMessages from queue and returns them as JSON.
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @return ResponseInterface
*/
public function getQueuedFlashMessagesAction(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
public function getQueuedFlashMessagesAction(ServerRequestInterface $request): ResponseInterface
{
$flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
$defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
......@@ -47,7 +47,6 @@ class FlashMessageController
];
}
$response->getBody()->write(json_encode($messages));
return $response;
return GeneralUtility::makeInstance(JsonResponse::class)->setPayload($messages);
}
}
......@@ -21,6 +21,7 @@ use TYPO3\CMS\Backend\Form\FormDataCompiler;
use TYPO3\CMS\Backend\Form\FormDataGroup\TcaDatabaseRecord;
use TYPO3\CMS\Backend\Form\NodeFactory;
use TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools;
use TYPO3\CMS\Core\Http\JsonResponse;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\StringUtility;
......@@ -34,10 +35,9 @@ class FormFlexAjaxController extends AbstractFormEngineAjaxController
* Render a single flex form section container to add it to the DOM
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @return ResponseInterface
*/
public function containerAdd(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
public function containerAdd(ServerRequestInterface $request): ResponseInterface
{
$queryParameters = $request->getParsedBody();
......@@ -180,8 +180,6 @@ class FormFlexAjaxController extends AbstractFormEngineAjaxController
$requireJsModule = $this->createExecutableStringRepresentationOfRegisteredRequireJsModules($newContainerResult);
$jsonResult['scriptCall'] = array_merge($requireJsModule, $jsonResult['scriptCall']);
$response->getBody()->write(json_encode($jsonResult));
return $response;
return GeneralUtility::makeInstance(JsonResponse::class, $jsonResult);
}
}
......@@ -23,6 +23,7 @@ use TYPO3\CMS\Backend\Form\InlineStackProcessor;
use TYPO3\CMS\Backend\Form\NodeFactory;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\DataHandling\DataHandler;
use TYPO3\CMS\Core\Http\JsonResponse;
use TYPO3\CMS\Core\Messaging\AbstractMessage;
use TYPO3\CMS\Core\Messaging\FlashMessageService;
use TYPO3\CMS\Core\Utility\ArrayUtility;
......@@ -38,10 +39,9 @@ class FormInlineAjaxController extends AbstractFormEngineAjaxController
* Create a new inline child via AJAX.
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @return ResponseInterface
*/
public function createAction(ServerRequestInterface $request, ResponseInterface $response)
public function createAction(ServerRequestInterface $request): ResponseInterface
{
$ajaxArguments = isset($request->getParsedBody()['ajax']) ? $request->getParsedBody()['ajax'] : $request->getQueryParams()['ajax'];
$parentConfig = $this->extractSignedParentConfigFromRequest((string)$ajaxArguments['context']);
......@@ -162,19 +162,16 @@ class FormInlineAjaxController extends AbstractFormEngineAjaxController
// Fade out and fade in the new record in the browser view to catch the user's eye
$jsonArray['scriptCall'][] = 'inline.fadeOutFadeIn(' . GeneralUtility::quoteJSvalue($objectId . '_div') . ');';
$response->getBody()->write(json_encode($jsonArray));
return $response;
return GeneralUtility::makeInstance(JsonResponse::class, $jsonArray);
}
/**
* Show the details of a child record.
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @return ResponseInterface
*/
public function detailsAction(ServerRequestInterface $request, ResponseInterface $response)
public function detailsAction(ServerRequestInterface $request): ResponseInterface
{
$ajaxArguments = isset($request->getParsedBody()['ajax']) ? $request->getParsedBody()['ajax'] : $request->getQueryParams()['ajax'];
......@@ -246,9 +243,7 @@ class FormInlineAjaxController extends AbstractFormEngineAjaxController
$jsonArray['scriptCall'][] = 'inline.collapseAllRecords(' . GeneralUtility::quoteJSvalue($objectId) . ',' . GeneralUtility::quoteJSvalue($objectPrefix) . ',\'' . (int)$child['uid'] . '\');';
}
$response->getBody()->write(json_encode($jsonArray));
return $response;
return GeneralUtility::makeInstance(JsonResponse::class, $jsonArray);
}
/**
......@@ -256,10 +251,9 @@ class FormInlineAjaxController extends AbstractFormEngineAjaxController
* Handle AJAX calls to localize all records of a parent, localize a single record or to synchronize with the original language parent.
*
* @param ServerRequestInterface $request the incoming request
* @param ResponseInterface $response the empty response
* @return ResponseInterface the filled response
*/
public function synchronizeLocalizeAction(ServerRequestInterface $request, ResponseInterface $response)
public function synchronizeLocalizeAction(ServerRequestInterface $request): ResponseInterface
{
$ajaxArguments = isset($request->getParsedBody()['ajax']) ? $request->getParsedBody()['ajax'] : $request->getQueryParams()['ajax'];
$domObjectId = $ajaxArguments[0];
......@@ -273,7 +267,11 @@ class FormInlineAjaxController extends AbstractFormEngineAjaxController
$inlineStackProcessor->injectAjaxConfiguration($parentConfig);
$inlineFirstPid = $this->getInlineFirstPidFromDomObjectId($domObjectId);
$jsonArray = false;
$jsonArray = [
'data' => '',
'stylesheetFiles' => [],
'scriptCall' => [],
];
if ($type === 'localize' || $type === 'synchronize' || MathUtility::canBeInterpretedAsInteger($type)) {
// Parent, this table embeds the child table
$parent = $inlineStackProcessor->getStructureLevel(-1);
......@@ -339,11 +337,6 @@ class FormInlineAjaxController extends AbstractFormEngineAjaxController
$newItemList = $tce->registerDBList[$parent['table']][$parent['uid']][$parentFieldName];
$jsonArray = [
'data' => '',
'stylesheetFiles' => [],
'scriptCall' => [],
];
$nameObject = $inlineStackProcessor->getCurrentStructureDomObjectIdPrefix($inlineFirstPid);
$nameObjectForeignTable = $nameObject . '-' . $child['table'];
......@@ -408,20 +401,16 @@ class FormInlineAjaxController extends AbstractFormEngineAjaxController
. ', json.data);';
}
}
$response->getBody()->write(json_encode($jsonArray));
return $response;
return GeneralUtility::makeInstance(JsonResponse::class)->setPayload($jsonArray);
}
/**
* Store status of inline children expand / collapse state in backend user uC.
*
* @param ServerRequestInterface $request the incoming request
* @param ResponseInterface $response the empty response
* @return ResponseInterface the filled response
*/
public function expandOrCollapseAction(ServerRequestInterface $request, ResponseInterface $response)
public function expandOrCollapseAction(ServerRequestInterface $request): ResponseInterface
{
$ajaxArguments = isset($request->getParsedBody()['ajax']) ? $request->getParsedBody()['ajax'] : $request->getQueryParams()['ajax'];
$domObjectId = $ajaxArguments[0];
......@@ -461,9 +450,7 @@ class FormInlineAjaxController extends AbstractFormEngineAjaxController
$backendUser->writeUC();
}
}
$response->getBody()->write(json_encode([]));
return $response;
return GeneralUtility::makeInstance(JsonResponse::class)->setPayload([]);
}
/**
......
......@@ -19,6 +19,7 @@ use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Form\FormDataCompiler;
use TYPO3\CMS\Backend\Form\FormDataGroup\TcaSelectTreeAjaxFieldData;
use TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools;
use TYPO3\CMS\Core\Http\JsonResponse;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
......@@ -30,11 +31,10 @@ class FormSelectTreeAjaxController
* Returns json representing category tree
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @throws \RuntimeException
* @return ResponseInterface
*/
public function fetchDataAction(ServerRequestInterface $request, ResponseInterface $response)
public function fetchDataAction(ServerRequestInterface $request): ResponseInterface
{
$tableName = $request->getQueryParams()['tableName'];
$fieldName = $request->getQueryParams()['fieldName'];
......@@ -179,8 +179,6 @@ class FormSelectTreeAjaxController
} else {
$treeData = $formData['processedTca']['columns'][$fieldName]['config']['items'];
}
$response->getBody()->write(json_encode($treeData));
return $response;
return GeneralUtility::makeInstance(JsonResponse::class)->setPayload($treeData);
}
}
......@@ -17,6 +17,7 @@ namespace TYPO3\CMS\Backend\Controller;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Http\JsonResponse;
use TYPO3\CMS\Core\LinkHandling\LinkService;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\GeneralUtility;
......@@ -81,10 +82,9 @@ class LinkBrowserController extends AbstractLinkBrowserController
* This avoids to implement the encoding functionality again in JS for the browser.
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @return ResponseInterface
*/
public function encodeTypoLink(ServerRequestInterface $request, ResponseInterface $response)
public function encodeTypoLink(ServerRequestInterface $request): ResponseInterface
{
$typoLinkParts = $request->getQueryParams();
if (isset($typoLinkParts['params'])) {
......@@ -93,9 +93,7 @@ class LinkBrowserController extends AbstractLinkBrowserController
}
$typoLink = GeneralUtility::makeInstance(TypoLinkCodecService::class)->encode($typoLinkParts);
$response->getBody()->write(json_encode(['typoLink' => $typoLink]));
return $response;
return GeneralUtility::makeInstance(JsonResponse::class, ['typoLink' => $typoLink]);
}
/**
......
......@@ -18,6 +18,7 @@ use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Search\LiveSearch\LiveSearch;
use TYPO3\CMS\Backend\Search\LiveSearch\QueryParser;
use TYPO3\CMS\Core\Http\JsonResponse;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
......@@ -34,10 +35,9 @@ class LiveSearchController
* Processes all AJAX calls and sends back a JSON object
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @return ResponseInterface
*/
public function liveSearchAction(ServerRequestInterface $request, ResponseInterface $response)
public function liveSearchAction(ServerRequestInterface $request): ResponseInterface
{
$queryString = $request->getQueryParams()['q'];
$liveSearch = GeneralUtility::makeInstance(LiveSearch::class);
......@@ -59,7 +59,6 @@ class LiveSearchController
$searchResults[] = $item;
}
}
$response->getBody()->write(json_encode($searchResults));
return $response;
return GeneralUtility::makeInstance(JsonResponse::class)->setPayload($searchResults);
}
}
......@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Backend\Controller;