diff --git a/typo3/sysext/t3editor/Classes/Controller/CodeCompletionController.php b/typo3/sysext/t3editor/Classes/Controller/CodeCompletionController.php index a9e9980d8af151969dc188ca93838fcbedb3abba..b10bf7c0efc04721fa2472bfa4451a6ba65d5695 100644 --- a/typo3/sysext/t3editor/Classes/Controller/CodeCompletionController.php +++ b/typo3/sysext/t3editor/Classes/Controller/CodeCompletionController.php @@ -17,56 +17,36 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use TYPO3\CMS\Core\Http\HtmlResponse; use TYPO3\CMS\Core\Http\JsonResponse; +use TYPO3\CMS\Core\Localization\LanguageService; +use TYPO3\CMS\Core\TypoScript\ExtendedTemplateService; +use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Core\Utility\RootlineUtility; /** * Code completion for t3editor */ class CodeCompletionController { - /** - * @var \TYPO3\CMS\Core\Http\AjaxRequestHandler - */ - protected $ajaxObj; - - /** - * Default constructor - */ - public function __construct() - { - $GLOBALS['LANG']->includeLLFile('EXT:t3editor/Resources/Private/Language/locallang.xlf'); - } - - /** - * General processor for AJAX requests. - * Called by AjaxRequestHandler - * - * @param ServerRequestInterface $request - * @return ResponseInterface - */ - public function loadCompletions(ServerRequestInterface $request): ResponseInterface - { - $pageId = (int)($request->getParsedBody()['pageId'] ?? $request->getQueryParams()['pageId']); - return $this->loadTemplates($pageId); - } - /** * Loads all templates up to a given page id (walking the rootline) and * cleans parts that are not required for the t3editor codecompletion. * - * @param int $pageId ID of the page + * @param ServerRequestInterface $request * @return ResponseInterface */ - protected function loadTemplates($pageId): ResponseInterface + public function loadCompletions(ServerRequestInterface $request): ResponseInterface { // Check whether access is granted (only admin have access to sys_template records): - if ($GLOBALS['BE_USER']->isAdmin()) { - // Check whether there is a pageId given: - if ($pageId) { - return (new JsonResponse())->setPayload($this->getMergedTemplates($pageId)); - } - return new HtmlResponse($GLOBALS['LANG']->getLL('pageIDInteger'), 500); + if (!$GLOBALS['BE_USER']->isAdmin()) { + return new HtmlResponse($this->getLanguageService()->sL('LLL:EXT:t3editor/Resources/Private/Language/locallang.xlf:noPermission'), 500); } - return new HtmlResponse($GLOBALS['LANG']->getLL('noPermission'), 500); + $pageId = (int)($request->getParsedBody()['pageId'] ?? $request->getQueryParams()['pageId']); + // Check whether there is a pageId given: + if (!$pageId) { + return new HtmlResponse($this->getLanguageService()->sL('LLL:EXT:t3editor/Resources/Private/Language/locallang.xlf:pageIDInteger'), 500); + } + // Fetch the templates + return (new JsonResponse())->setPayload($this->getMergedTemplates($pageId)); } /** @@ -78,12 +58,10 @@ class CodeCompletionController */ protected function getMergedTemplates($pageId) { - /** @var $tsParser \TYPO3\CMS\Core\TypoScript\ExtendedTemplateService */ - $tsParser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\ExtendedTemplateService::class); + $tsParser = GeneralUtility::makeInstance(ExtendedTemplateService::class); $tsParser->init(); // Gets the rootLine - $page = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Page\PageRepository::class); - $rootLine = $page->getRootLine($pageId); + $rootLine = GeneralUtility::makeInstance(RootlineUtility::class, $pageId)->get(); // This generates the constants/config + hierarchy info for the template. $tsParser->runThroughTemplates($rootLine); // ts-setup & ts-constants of the currently edited template should not be included @@ -110,7 +88,7 @@ class CodeCompletionController foreach ($treeBranch as $key => $value) { $dotCount = substr_count($key, '.'); //type definition or value-assignment - if ($dotCount == 0) { + if ($dotCount === 0) { if ($value != '') { if (strlen($value) > 20) { $value = substr($value, 0, 20); @@ -134,4 +112,12 @@ class CodeCompletionController } return $cleanedTreeBranch; } + + /** + * @return LanguageService + */ + protected function getLanguageService(): LanguageService + { + return $GLOBALS['LANG']; + } } diff --git a/typo3/sysext/t3editor/Classes/Controller/TypoScriptReferenceController.php b/typo3/sysext/t3editor/Classes/Controller/TypoScriptReferenceController.php index 74837b72aacb09e7149c92aa5e01b0444bae6c72..860e61c7b2df59543e4695dfe7842f96feaf7d09 100644 --- a/typo3/sysext/t3editor/Classes/Controller/TypoScriptReferenceController.php +++ b/typo3/sysext/t3editor/Classes/Controller/TypoScriptReferenceController.php @@ -28,14 +28,6 @@ class TypoScriptReferenceController */ protected $xmlDoc; - /** - * Default constructor - */ - public function __construct() - { - $GLOBALS['LANG']->includeLLFile('EXT:t3editor/Resources/Private/Language/locallang.xlf'); - } - /** * Load TypoScript reference * diff --git a/typo3/sysext/t3editor/Classes/T3editor.php b/typo3/sysext/t3editor/Classes/T3editor.php index 8faf3e0a6393e261c99659b124d9bae3753d01a2..172bdae8f4db2ba15769ede1baa0bc4fc8c62b69 100644 --- a/typo3/sysext/t3editor/Classes/T3editor.php +++ b/typo3/sysext/t3editor/Classes/T3editor.php @@ -143,7 +143,7 @@ class T3editor implements SingletonInterface } /** - * @return PhpFrontend + * @return FrontendInterface * @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException * @throws \InvalidArgumentException */