[TASK] Use ServerRequestInterface in LogoutController
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / ContextMenuController.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Backend\Controller;
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;
20 use TYPO3\CMS\Backend\Clipboard\Clipboard;
21 use TYPO3\CMS\Backend\ContextMenu\ContextMenu;
22 use TYPO3\CMS\Core\Http\JsonResponse;
23 use TYPO3\CMS\Core\Localization\LanguageService;
24 use TYPO3\CMS\Core\Utility\GeneralUtility;
25
26 /**
27 * Script Class for the Context Sensitive Menu in TYPO3
28 */
29 class ContextMenuController
30 {
31 /**
32 * Constructor
33 */
34 public function __construct()
35 {
36 $this->getLanguageService()->includeLLFile('EXT:lang/Resources/Private/Language/locallang_misc.xlf');
37 }
38
39 /**
40 * Renders a context menu
41 *
42 * @param ServerRequestInterface $request
43 * @return ResponseInterface
44 */
45 public function getContextMenuAction(ServerRequestInterface $request): ResponseInterface
46 {
47 $contextMenu = GeneralUtility::makeInstance(ContextMenu::class);
48
49 $params = $request->getQueryParams();
50 $context = $params['context'] ?? '';
51 $items = $contextMenu->getItems($params['table'], $params['uid'], $context);
52 if (!is_array($items)) {
53 $items = [];
54 }
55 return (new JsonResponse())->setPayload($items);
56 }
57
58 /**
59 * @param ServerRequestInterface $request
60 * @return ResponseInterface
61 */
62 public function clipboardAction(ServerRequestInterface $request): ResponseInterface
63 {
64 /** @var Clipboard $clipboard */
65 $clipboard = GeneralUtility::makeInstance(Clipboard::class);
66 $clipboard->initializeClipboard();
67 $clipboard->lockToNormal();
68
69 $clipboard->setCmd($request->getQueryParams()['CB']);
70 $clipboard->cleanCurrent();
71
72 $clipboard->endClipboard();
73 return (new JsonResponse())->setPayload([]);
74 }
75
76 /**
77 * Returns LanguageService
78 *
79 * @return LanguageService
80 */
81 protected function getLanguageService(): LanguageService
82 {
83 return $GLOBALS['LANG'];
84 }
85 }