24428afae3de19f4c6a8c60bae72eab15dae78f7
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / ClickMenuController.php
1 <?php
2 namespace TYPO3\CMS\Backend\Controller;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use Psr\Http\Message\ResponseInterface;
18 use Psr\Http\Message\ServerRequestInterface;
19 use TYPO3\CMS\Backend\ClickMenu\ClickMenu;
20 use TYPO3\CMS\Backend\Clipboard\Clipboard;
21 use TYPO3\CMS\Core\Utility\GeneralUtility;
22
23 /**
24 * Script Class for the Context Sensitive Menu in TYPO3 (rendered in top frame, normally writing content dynamically to list frames).
25 * @see \TYPO3\CMS\Backend\Template\DocumentTemplate::getContextMenuCode()
26 */
27 class ClickMenuController
28 {
29 /**
30 * Constructor
31 */
32 public function __construct()
33 {
34 $this->getLanguageService()->includeLLFile('EXT:lang/locallang_misc.xlf');
35 $GLOBALS['SOBE'] = $this;
36 // Setting pseudo module name
37 $this->MCONF['name'] = 'xMOD_alt_clickmenu.php';
38 }
39
40 /**
41 * this is an intermediate clickmenu handler
42 *
43 * @param ServerRequestInterface $request
44 * @param ResponseInterface $response
45 * @return ResponseInterface
46 */
47 public function getContextMenuAction(ServerRequestInterface $request, ResponseInterface $response)
48 {
49 /** @var Clipboard $clipObj */
50 $clipObj = GeneralUtility::makeInstance(Clipboard::class);
51 $clipObj->initializeClipboard();
52 // This locks the clipboard to the Normal for this request.
53 $clipObj->lockToNormal();
54 // Update clipboard if some actions are sent.
55 $clipObj->setCmd($request->getQueryParams()['CB']);
56 $clipObj->cleanCurrent();
57 // Saves
58 $clipObj->endClipboard();
59 // Create clickmenu object
60 $clickMenu = GeneralUtility::makeInstance(ClickMenu::class);
61 // Set internal vars in clickmenu object:
62 $clickMenu->clipObj = $clipObj;
63 // Setting internal array of classes for extending the clickmenu:
64 $clickMenu->extClassArray = $GLOBALS['TBE_MODULES_EXT']['xMOD_alt_clickmenu']['extendCMclasses'];
65
66 $content = $clickMenu->init();
67 if (is_array($content)) {
68 $response->getBody()->write(json_encode($content));
69 }
70 return $response;
71 }
72
73 /**
74 * Returns LanguageService
75 *
76 * @return \TYPO3\CMS\Lang\LanguageService
77 */
78 protected function getLanguageService()
79 {
80 return $GLOBALS['LANG'];
81 }
82 }