‪TYPO3CMS  9.5
UserSettingsController.php
Go to the documentation of this file.
1 <?php
2 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 
18 use Psr\Http\Message\ResponseInterface;
19 use Psr\Http\Message\ServerRequestInterface;
23 
30 {
35 
39  public function ‪__construct()
40  {
41  $this->backendUserConfiguration = GeneralUtility::makeInstance(BackendUserConfiguration::class);
42  }
43 
50  public function ‪processAjaxRequest(ServerRequestInterface $request): ResponseInterface
51  {
52  // do the regular / main logic, depending on the action parameter
53  $action = $request->getParsedBody()['action'] ?? $request->getQueryParams()['action'] ?? '';
54  $key = $request->getParsedBody()['key'] ?? $request->getQueryParams()['key'] ?? '';
55  $value = $request->getParsedBody()['value'] ?? $request->getQueryParams()['value'] ?? '';
56  $data = $this->‪processRequest($action, $key, $value);
57 
58  return (new ‪JsonResponse())->setPayload($data);
59  }
60 
71  public function ‪process($action, $key = '', $value = '')
72  {
73  trigger_error('UserSettingsController->process() will be replaced by protected method processRequest() in TYPO3 v10.0. Do not call from other extensions.', E_USER_DEPRECATED);
74  return $this->‪processRequest($action, $key, $value);
75  }
76 
85  protected function ‪processRequest(string $action, string $key = '', $value = '')
86  {
87  switch ($action) {
88  case 'get':
89  $content = $this->backendUserConfiguration->get($key);
90  break;
91  case 'getAll':
92  $content = $this->backendUserConfiguration->getAll();
93  break;
94  case 'set':
95  $this->backendUserConfiguration->set($key, $value);
96  $content = $this->backendUserConfiguration->getAll();
97  break;
98  case 'addToList':
99  $this->backendUserConfiguration->addToList($key, $value);
100  $content = $this->backendUserConfiguration->getAll();
101  break;
102  case 'removeFromList':
103  $this->backendUserConfiguration->removeFromList($key, $value);
104  $content = $this->backendUserConfiguration->getAll();
105  break;
106  case 'unset':
107  $this->backendUserConfiguration->unsetOption($key);
108  $content = $this->backendUserConfiguration->getAll();
109  break;
110  case 'clear':
111  $this->backendUserConfiguration->clear();
112  $content = ['result' => true];
113  break;
114  default:
115  $content = ['result' => false];
116  }
117 
118  return $content;
119  }
120 }
‪TYPO3\CMS\Backend\Controller\UserSettingsController\__construct
‪__construct()
Definition: UserSettingsController.php:38
‪TYPO3\CMS\Backend\Controller\UserSettingsController\processRequest
‪mixed processRequest(string $action, string $key='', $value='')
Definition: UserSettingsController.php:84
‪TYPO3\CMS\Backend\Controller\UserSettingsController\processAjaxRequest
‪ResponseInterface processAjaxRequest(ServerRequestInterface $request)
Definition: UserSettingsController.php:49
‪TYPO3\CMS\Backend\Controller\UserSettingsController
Definition: UserSettingsController.php:30
‪TYPO3\CMS\Backend\Controller\UserSettingsController\$backendUserConfiguration
‪BackendUserConfiguration $backendUserConfiguration
Definition: UserSettingsController.php:33
‪TYPO3\CMS\Backend\Configuration\BackendUserConfiguration
Definition: BackendUserConfiguration.php:28
‪TYPO3\CMS\Backend\Controller\UserSettingsController\process
‪mixed process($action, $key='', $value='')
Definition: UserSettingsController.php:70
‪TYPO3\CMS\Core\Http\JsonResponse
Definition: JsonResponse.php:25
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Backend\Controller
Definition: AbstractFormEngineAjaxController.php:3