uc * used for AJAX and Storage/Persistent JS object * @internal This class is a specific Backend controller implementation and is not considered part of the Public TYPO3 API. */ class UserSettingsController { private const array ALLOWED_ACTIONS = [ 'GET' => ['get', 'getAll'], 'POST' => ['set', 'addToList', 'removeFromList', 'unset', 'clear'], ]; /** * Processes all AJAX calls and returns a JSON for the data */ public function processAjaxRequest(ServerRequestInterface $request): ResponseInterface { // do the regular / main logic, depending on the action parameter $action = $this->getValidActionFromRequest($request); $key = $request->getParsedBody()['key'] ?? $request->getQueryParams()['key'] ?? ''; $value = $request->getParsedBody()['value'] ?? $request->getQueryParams()['value'] ?? ''; $backendUserConfiguration = GeneralUtility::makeInstance(BackendUserConfiguration::class); switch ($action) { case 'get': $content = $backendUserConfiguration->get($key); break; case 'getAll': $content = $backendUserConfiguration->getAll(); break; case 'set': $backendUserConfiguration->set($key, $value); $content = $backendUserConfiguration->getAll(); break; case 'addToList': $backendUserConfiguration->addToList($key, $value); $content = $backendUserConfiguration->getAll(); break; case 'removeFromList': $backendUserConfiguration->removeFromList($key, $value); $content = $backendUserConfiguration->getAll(); break; case 'unset': $backendUserConfiguration->unsetOption($key); $content = $backendUserConfiguration->getAll(); break; case 'clear': $backendUserConfiguration->clear(); $content = ['result' => true]; break; default: $content = ['result' => false]; } return new JsonResponse($content); } protected function getValidActionFromRequest(ServerRequestInterface $request): string { $action = $request->getParsedBody()['action'] ?? $request->getQueryParams()['action'] ?? ''; return in_array($action, (self::ALLOWED_ACTIONS[$request->getMethod()] ?? []), true) ? $action : ''; } }