responseFactory = $responseFactory; $this->streamFactory = $streamFactory; $this->clipboard = GeneralUtility::makeInstance(Clipboard::class); } /** * Process incoming clipboard request */ public function processRequest(ServerRequestInterface $request): ResponseInterface { $this->clipboard->initializeClipboard($request); $CB = (array)($request->getParsedBody()['CB'] ?? []); if ($CB !== []) { // Execute commands. $this->clipboard->setCmd($CB); } // Clean up pad $this->clipboard->cleanCurrent(); // Save the clipboard content $this->clipboard->endClipboard(); $action = (string)($request->getQueryParams()['action'] ?? ''); if (in_array($action, self::ALLOWED_ACTIONS, true)) { return $this->{$action . 'Action'}($request); } // Default response in case no dedicated action is requested. // This is usually done if only internal clipboard state is changed. return $this->createResponse(['success' => true, 'data' => []]); } protected function getClipboardDataAction(ServerRequestInterface $request): ResponseInterface { $clipboardData = $this->clipboard->getClipboardData($request->getParsedBody()['table'] ?? ''); // Add labels for the panel $lang = $this->getLanguageService(); $clipboardLabels = [ 'clipboard' => $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:buttons.clipboard'), 'copyElements' => $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_misc.xlf:copyElements'), 'moveElements' => $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_misc.xlf:moveElements'), 'copy' => $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.copy'), 'cut' => $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.cut'), 'info' => $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.info'), 'removeAll' => $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:buttons.removeAll'), 'removeItem' => $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.removeItem'), ]; return $this->createResponse([ 'success' => $clipboardData !== [], 'data' => array_merge($clipboardData, ['labels' => $clipboardLabels]), ]); } protected function createResponse(array $data): ResponseInterface { return $this->responseFactory->createResponse() ->withHeader('Content-Type', 'application/json; charset=utf-8') ->withBody($this->streamFactory->createStream(json_encode($data))); } protected function getLanguageService(): LanguageService { return $GLOBALS['LANG']; } }