‪TYPO3CMS  10.4
UserSettingsController.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Http\Message\ResponseInterface;
21 use Psr\Http\Message\ServerRequestInterface;
25 
32 {
39  public function ‪processAjaxRequest(ServerRequestInterface $request): ResponseInterface
40  {
41  // do the regular / main logic, depending on the action parameter
42  $action = $request->getParsedBody()['action'] ?? $request->getQueryParams()['action'] ?? '';
43  $key = $request->getParsedBody()['key'] ?? $request->getQueryParams()['key'] ?? '';
44  $value = $request->getParsedBody()['value'] ?? $request->getQueryParams()['value'] ?? '';
45  $backendUserConfiguration = GeneralUtility::makeInstance(BackendUserConfiguration::class);
46  switch ($action) {
47  case 'get':
48  $content = $backendUserConfiguration->get($key);
49  break;
50  case 'getAll':
51  $content = $backendUserConfiguration->getAll();
52  break;
53  case 'set':
54  $backendUserConfiguration->set($key, $value);
55  $content = $backendUserConfiguration->getAll();
56  break;
57  case 'addToList':
58  $backendUserConfiguration->addToList($key, $value);
59  $content = $backendUserConfiguration->getAll();
60  break;
61  case 'removeFromList':
62  $backendUserConfiguration->removeFromList($key, $value);
63  $content = $backendUserConfiguration->getAll();
64  break;
65  case 'unset':
66  $backendUserConfiguration->unsetOption($key);
67  $content = $backendUserConfiguration->getAll();
68  break;
69  case 'clear':
70  $backendUserConfiguration->clear();
71  $content = ['result' => true];
72  break;
73  default:
74  $content = ['result' => false];
75  }
76  return (new ‪JsonResponse())->setPayload($content);
77  }
78 }
‪TYPO3\CMS\Backend\Controller\UserSettingsController\processAjaxRequest
‪ResponseInterface processAjaxRequest(ServerRequestInterface $request)
Definition: UserSettingsController.php:39
‪TYPO3\CMS\Backend\Controller\UserSettingsController
Definition: UserSettingsController.php:32
‪TYPO3\CMS\Backend\Configuration\BackendUserConfiguration
Definition: BackendUserConfiguration.php:30
‪TYPO3\CMS\Core\Http\JsonResponse
Definition: JsonResponse.php:26
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Backend\Controller
Definition: AbstractFormEngineAjaxController.php:18