[BUGFIX] T3Editor getPlugins must write to response object 82/50882/2
authorMarkus Klein <markus.klein@typo3.org>
Fri, 25 Nov 2016 19:05:40 +0000 (20:05 +0100)
committerWouter Wolters <typo3@wouterwolters.nl>
Sun, 4 Dec 2016 12:58:46 +0000 (13:58 +0100)
Fix the ajax request target getPlugins to write its response to
the response object and not to the request.

Moreover fix return value of setModeByFile, which is used
only once, but does not need a return value at all.

Resolves: #78802
Releases: master, 7.6
Change-Id: I840de6fe851a3c4e104c4de1ee9bd0e9c4d8f3c6
Reviewed-on: https://review.typo3.org/50882
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/t3editor/Classes/T3editor.php

index 0452389..f923b6b 100644 (file)
@@ -16,7 +16,9 @@ namespace TYPO3\CMS\T3editor;
 
 use Psr\Http\Message\ResponseInterface;
 use Psr\Http\Message\ServerRequestInterface;
+use TYPO3\CMS\Core\Http\Response;
 use TYPO3\CMS\Core\Page\PageRenderer;
+use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
@@ -99,13 +101,12 @@ class T3editor implements \TYPO3\CMS\Core\SingletonInterface
      * Set mode by file
      *
      * @param string $file
-     * @return string
+     * @return void
      */
     public function setModeByFile($file)
     {
         $fileInfo = GeneralUtility::split_fileref($file);
-        // @TODO: @FIXME: the method setModeByType returns void, so this method will never return a string
-        return $this->setModeByType($fileInfo['fileext']);
+        $this->setModeByType($fileInfo['fileext']);
     }
 
     /**
@@ -178,7 +179,7 @@ class T3editor implements \TYPO3\CMS\Core\SingletonInterface
         // Disable pmktextarea to avoid conflicts (thanks Peter Klein for this suggestion)
         $GLOBALS['BE_USER']->uc['disablePMKTextarea'] = 1;
 
-        $this->relExtPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('t3editor');
+        $this->relExtPath = ExtensionManagementUtility::extRelPath('t3editor');
         $this->codemirrorPath = $this->relExtPath . $this->codemirrorPath;
     }
 
@@ -248,6 +249,8 @@ class T3editor implements \TYPO3\CMS\Core\SingletonInterface
             case self::MODE_MIXED:
                 $parserfile = ['tokenizejavascript.js', 'parsejavascript.js', 'parsecss.js', 'parsexml.js', '../contrib/php/js/tokenizephp.js', '../contrib/php/js/parsephp.js', '../contrib/php/js/parsephphtmlmixed.js'];
                 break;
+            default:
+                $parserfile = [];
         }
         return json_encode($parserfile);
     }
@@ -371,8 +374,8 @@ class T3editor implements \TYPO3\CMS\Core\SingletonInterface
                     'exceptionCode' => $e->getCode()
                 ];
             }
-            /** @var \TYPO3\CMS\Core\Http\Response $response */
-            $response = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Http\Response::class);
+            /** @var Response $response */
+            $response = GeneralUtility::makeInstance(Response::class);
             $response->getBody()->write(json_encode($responseContent));
         }
 
@@ -394,8 +397,8 @@ class T3editor implements \TYPO3\CMS\Core\SingletonInterface
         if (is_array($plugins)) {
             $result = array_values($plugins);
         }
-        $request->getBody()->write(json_encode($result));
-        return $request;
+        $response->getBody()->write(json_encode($result));
+        return $response;
     }
 
     /**