[!!!][FEATURE] Introduce PSR-7-based Routing for Backend AJAX Requests
[Packages/TYPO3.CMS.git] / typo3 / sysext / opendocs / Classes / Backend / ToolbarItems / OpendocsToolbarItem.php
index 8d5bcb4..f8a3876 100644 (file)
@@ -14,6 +14,8 @@ namespace TYPO3\CMS\Opendocs\Backend\ToolbarItems;
  * The TYPO3 project - inspiring people to share!
  */
 
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
 use TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface;
 use TYPO3\CMS\Core\Imaging\Icon;
 use TYPO3\CMS\Core\Imaging\IconFactory;
@@ -212,13 +214,13 @@ class OpendocsToolbarItem implements ToolbarItemInterface {
        /**
         * Closes a document in the session and
         *
-        * @param array $params Array of parameters from the AJAX interface, currently unused
-        * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj Object of type AjaxRequestHandler
-        * @return string List item HTML attributes
+        * @param ServerRequestInterface $request
+        * @param ResponseInterface $response
+        * @return ResponseInterface
         */
-       public function closeDocument($params = array(), \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj = NULL) {
+       public function closeDocument(ServerRequestInterface $request, ResponseInterface $response) {
                $backendUser = $this->getBackendUser();
-               $md5sum = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('md5sum');
+               $md5sum = isset($request->getParsedBody()['md5sum']) ? $request->getParsedBody()['md5sum'] : $request->getQueryParams()['md5sum'];
                if ($md5sum && isset($this->openDocs[$md5sum])) {
                        // Add the document to be closed to the recent documents
                        $this->recentDocs = array_merge(array($md5sum => $this->openDocs[$md5sum]), $this->recentDocs);
@@ -232,18 +234,20 @@ class OpendocsToolbarItem implements ToolbarItemInterface {
                        $backendUser->pushModuleData('FormEngine', array($this->openDocs, $docDat));
                        $backendUser->pushModuleData('opendocs::recent', $this->recentDocs);
                }
-               $this->renderAjax($params, $ajaxObj);
+               return $this->renderMenu($request, $response);
        }
 
        /**
         * Renders the menu so that it can be returned as response to an AJAX call
         *
-        * @param array $params Array of parameters from the AJAX interface, currently unused
-        * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj Object of type AjaxRequestHandler
-        * @return void
+        * @param ServerRequestInterface $request
+        * @param ResponseInterface $response
+        * @return ResponseInterface
         */
-       public function renderAjax($params = array(), \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj = NULL) {
-               $ajaxObj->addContent('opendocsMenu', $this->getDropDown());
+       public function renderMenu(ServerRequestInterface $request, ResponseInterface $response) {
+               $response->getBody()->write($this->getDropDown());
+               $response = $response->withHeader('Content-Type', 'html');
+               return $response;
        }
 
        /**