[TASK] Remove usage of extbase from HelpController 47/56247/3
authorGeorg Ringer <georg.ringer@gmail.com>
Fri, 16 Mar 2018 18:16:47 +0000 (19:16 +0100)
committerAndreas Wolf <andreas.wolf@typo3.org>
Sun, 18 Mar 2018 11:07:00 +0000 (12:07 +0100)
Improve the performance by removing usage of extbase from the
HelpController.

Resolves: #84331
Releases: master
Change-Id: I3b7d82c1765a4888bd84d6938a65c546a25ba9d1
Reviewed-on: https://review.typo3.org/56247
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Andreas Wolf <andreas.wolf@typo3.org>
Tested-by: Andreas Wolf <andreas.wolf@typo3.org>
typo3/sysext/backend/Resources/Private/TypeScript/ContextHelp.ts
typo3/sysext/backend/Resources/Public/JavaScript/ContextHelp.js
typo3/sysext/documentation/Classes/Controller/DocumentController.php
typo3/sysext/documentation/Classes/Controller/HelpController.php
typo3/sysext/documentation/Classes/Service/JavaScriptService.php
typo3/sysext/documentation/Classes/Utility/LanguageUtility.php [deleted file]
typo3/sysext/documentation/Resources/Private/Partials/TableOfContents.html
typo3/sysext/documentation/Resources/Private/Templates/Help/Index.html
typo3/sysext/documentation/ext_tables.php

index 40fcfa7..8da2f89 100644 (file)
@@ -125,8 +125,8 @@ class ContextHelp {
     try {
       const cshWindow = window.open(
         this.helpModuleUrl +
-        '&tx_documentation_help_documentationcshmanual[table]=' + $trigger.data('table') +
-        '&tx_documentation_help_documentationcshmanual[field]=' + $trigger.data('field'),
+        '&table=' + $trigger.data('table') +
+        '&field=' + $trigger.data('field'),
         'ContextHelpWindow',
         'height=400,width=600,status=0,menubar=0,scrollbars=1'
       );
index d8b8821..127baaf 100644 (file)
@@ -10,4 +10,4 @@
  *
  * The TYPO3 project - inspiring people to share!
  */
-define(["require","exports","jquery","./Popover","bootstrap"],function(t,e,o,n){"use strict";return new(function(){function t(){this.ajaxUrl=TYPO3.settings.ajaxUrls.context_help,this.trigger="click",this.placement="auto",this.selector=".t3-help-link",this.initialize()}return t.resolveBackend=function(){return void 0!==window.opener&&null!==window.opener?window.opener.top:top},t.prototype.initialize=function(){var e=this,a=t.resolveBackend();void 0!==a.TYPO3.settings.ContextHelp&&(this.helpModuleUrl=a.TYPO3.settings.ContextHelp.moduleUrl),void 0===TYPO3.ShortcutMenu&&void 0===a.TYPO3.ShortcutMenu&&o(".icon-actions-system-shortcut-new").closest(".btn").hide();var i="&nbsp;";void 0!==a.TYPO3.lang&&(i=a.TYPO3.lang.csh_tooltip_loading);var r=o(this.selector);r.attr("data-loaded","false").attr("data-html","true").attr("data-original-title",i).attr("data-placement",this.placement).attr("data-trigger",this.trigger),n.popover(r),o(document).on("show.bs.popover",this.selector,function(t){var a=o(t.currentTarget),i=a.data("description");void 0!==i&&""!==i?n.setOptions(a,{title:a.data("title"),content:i}):"false"===a.attr("data-loaded")&&a.data("table")&&e.loadHelp(a),a.closest(".t3js-module-docheader").length&&n.setOption(a,"placement","bottom")}).on("shown.bs.popover",this.selector,function(t){var e=o(t.target).data("bs.popover").$tip;e.find(".popover-title").is(":visible")||e.addClass("no-title")}).on("click",".tipIsLinked",function(t){o(".popover").each(function(n,a){var i=o(a);i.has(t.target).length&&(console.log(i.data("bs.popover")),e.showHelpPopup(i.data("bs.popover").$element))})}).on("click","body",function(t){o(e.selector).each(function(e,a){var i=o(a);i.is(t.target)||0!==i.has(t.target).length||0!==o(".popover").has(t.target).length||n.hide(i)})})},t.prototype.showHelpPopup=function(t){try{var e=window.open(this.helpModuleUrl+"&tx_documentation_help_documentationcshmanual[table]="+t.data("table")+"&tx_documentation_help_documentationcshmanual[field]="+t.data("field"),"ContextHelpWindow","height=400,width=600,status=0,menubar=0,scrollbars=1");return e.focus(),n.hide(t),e}catch(t){}},t.prototype.loadHelp=function(t){var e=t.data("table"),a=t.data("field");e&&o.getJSON(this.ajaxUrl,{params:{action:"getContextHelp",table:e,field:a}}).done(function(e){var o=e.title||"",a=e.content||"<p></p>";n.setOptions(t,{title:o,content:a}),t.attr("data-loaded","true").one("hidden.bs.popover",function(){n.show(t)}),n.hide(t)})},t}())});
\ No newline at end of file
+define(["require","exports","jquery","./Popover","bootstrap"],function(t,e,o,a){"use strict";return new(function(){function t(){this.ajaxUrl=TYPO3.settings.ajaxUrls.context_help,this.trigger="click",this.placement="auto",this.selector=".t3-help-link",this.initialize()}return t.resolveBackend=function(){return void 0!==window.opener&&null!==window.opener?window.opener.top:top},t.prototype.initialize=function(){var e=this,n=t.resolveBackend();void 0!==n.TYPO3.settings.ContextHelp&&(this.helpModuleUrl=n.TYPO3.settings.ContextHelp.moduleUrl),void 0===TYPO3.ShortcutMenu&&void 0===n.TYPO3.ShortcutMenu&&o(".icon-actions-system-shortcut-new").closest(".btn").hide();var i="&nbsp;";void 0!==n.TYPO3.lang&&(i=n.TYPO3.lang.csh_tooltip_loading);var r=o(this.selector);r.attr("data-loaded","false").attr("data-html","true").attr("data-original-title",i).attr("data-placement",this.placement).attr("data-trigger",this.trigger),a.popover(r),o(document).on("show.bs.popover",this.selector,function(t){var n=o(t.currentTarget),i=n.data("description");void 0!==i&&""!==i?a.setOptions(n,{title:n.data("title"),content:i}):"false"===n.attr("data-loaded")&&n.data("table")&&e.loadHelp(n),n.closest(".t3js-module-docheader").length&&a.setOption(n,"placement","bottom")}).on("shown.bs.popover",this.selector,function(t){var e=o(t.target).data("bs.popover").$tip;e.find(".popover-title").is(":visible")||e.addClass("no-title")}).on("click",".tipIsLinked",function(t){o(".popover").each(function(a,n){var i=o(n);i.has(t.target).length&&(console.log(i.data("bs.popover")),e.showHelpPopup(i.data("bs.popover").$element))})}).on("click","body",function(t){o(e.selector).each(function(e,n){var i=o(n);i.is(t.target)||0!==i.has(t.target).length||0!==o(".popover").has(t.target).length||a.hide(i)})})},t.prototype.showHelpPopup=function(t){try{var e=window.open(this.helpModuleUrl+"&table="+t.data("table")+"&field="+t.data("field"),"ContextHelpWindow","height=400,width=600,status=0,menubar=0,scrollbars=1");return e.focus(),a.hide(t),e}catch(t){}},t.prototype.loadHelp=function(t){var e=t.data("table"),n=t.data("field");e&&o.getJSON(this.ajaxUrl,{params:{action:"getContextHelp",table:e,field:n}}).done(function(e){var o=e.title||"",n=e.content||"<p></p>";a.setOptions(t,{title:o,content:n}),t.attr("data-loaded","true").one("hidden.bs.popover",function(){a.show(t)}),a.hide(t)})},t}())});
\ No newline at end of file
index 6ca16b9..4f26d85 100644 (file)
@@ -24,7 +24,6 @@ use TYPO3\CMS\Core\Page\PageRenderer;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Documentation\Domain\Repository\DocumentRepository;
 use TYPO3\CMS\Documentation\Service\DocumentationService;
-use TYPO3\CMS\Documentation\Utility\LanguageUtility;
 use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
 use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
 use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
@@ -47,11 +46,6 @@ class DocumentController extends ActionController
     protected $documentationService;
 
     /**
-     * @var LanguageUtility
-     */
-    protected $languageUtility;
-
-    /**
      * @var Dispatcher
      */
     protected $signalSlotDispatcher;
@@ -132,14 +126,6 @@ class DocumentController extends ActionController
     }
 
     /**
-     * @param LanguageUtility $languageUtility
-     */
-    public function injectLanguageUtility(LanguageUtility $languageUtility)
-    {
-        $this->languageUtility = $languageUtility;
-    }
-
-    /**
      * @param Dispatcher $signalSlotDispatcher
      */
     public function injectSignalSlotDispatcher(Dispatcher $signalSlotDispatcher)
@@ -200,7 +186,7 @@ class DocumentController extends ActionController
      */
     public function getDocuments()
     {
-        $language = $this->languageUtility->getDocumentationLanguage();
+        $language =  $this->getBackendUser()->uc['lang'] ?: 'default';
         $documents = $this->documentRepository->findByLanguage($language);
 
         $documents = $this->emitAfterInitializeDocumentsSignal($language, $documents);
@@ -262,7 +248,7 @@ class DocumentController extends ActionController
             $this->redirect('list');
         }
 
-        $language = $this->languageUtility->getDocumentationLanguage();
+        $language = $this->getBackendUser()->uc['lang'] ?: 'default';
         try {
             $result = $this->documentationService->fetchNearestDocument($url, $key, $version ?: 'latest', $language);
             if ($result) {
index 3668f54..98c678e 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+declare(strict_types = 1);
 namespace TYPO3\CMS\Documentation\Controller;
 
 /*
@@ -14,21 +15,25 @@ namespace TYPO3\CMS\Documentation\Controller;
  * The TYPO3 project - inspiring people to share!
  */
 
-use TYPO3\CMS\Backend\Template\Components\ButtonBar;
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
+use TYPO3\CMS\Backend\Routing\UriBuilder;
+use TYPO3\CMS\Backend\Template\ModuleTemplate;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
-use TYPO3\CMS\Backend\View\BackendTemplateView;
 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
+use TYPO3\CMS\Core\Http\HtmlResponse;
+use TYPO3\CMS\Core\Http\RedirectResponse;
 use TYPO3\CMS\Core\Imaging\Icon;
 use TYPO3\CMS\Core\Localization\LanguageService;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Documentation\Domain\Repository\TableManualRepository;
-use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
-use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
+use TYPO3\CMS\Fluid\View\StandaloneView;
+use TYPO3Fluid\Fluid\View\ViewInterface;
 
 /**
  * Main help module controller
  */
-class HelpController extends ActionController
+class HelpController
 {
     /**
      * Section identifiers
@@ -45,32 +50,66 @@ class HelpController extends ActionController
      */
     protected $tableManualRepository;
 
-    /**
-     * Default View Container
-     *
-     * @var BackendTemplateView
-     */
-    protected $defaultViewObjectName = BackendTemplateView::class;
+    /** @var ModuleTemplate */
+    protected $moduleTemplate;
+
+    /** @var ViewInterface */
+    protected $view;
 
     /**
-     * Initialize the controller
+     * Instantiate the report controller
      */
-    public function initializeAction()
+    public function __construct()
     {
+        $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
         $this->tableManualRepository = GeneralUtility::makeInstance(TableManualRepository::class);
     }
 
     /**
-     * Initialize the view
+     * Injects the request object for the current request, and renders correct action
      *
-     * @param ViewInterface $view The view
+     * @param ServerRequestInterface $request the current request
+     * @return ResponseInterface the response with the content
      */
-    public function initializeView(ViewInterface $view)
+    public function handleRequest(ServerRequestInterface $request): ResponseInterface
     {
-        /** @var BackendTemplateView $view */
-        parent::initializeView($view);
-        $this->registerDocheaderButtons();
-        $view->assign('copyright', BackendUtility::TYPO3_copyRightNotice());
+        $action = $request->getQueryParams()['action'] ?? $request->getParsedBody()['action'] ?? 'index';
+
+        if ($action === 'detail') {
+            $table = $request->getQueryParams()['table'] ?? $request->getParsedBody()['table'];
+            if (!$table) {
+                $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
+                return new RedirectResponse((string)$uriBuilder->buildUriFromRoute('help_cshmanual', [
+                    'action' => 'index',
+                ]), 303);
+            }
+        }
+
+        $this->initializeView($action);
+
+        $result = call_user_func_array([$this, $action . 'Action'], [$request]);
+        if ($result instanceof ResponseInterface) {
+            return $result;
+        }
+
+        $this->registerDocheaderButtons($request);
+
+        $this->moduleTemplate->setContent($this->view->render());
+        return new HtmlResponse($this->moduleTemplate->renderContent());
+    }
+
+    /**
+     * @param string $templateName
+     */
+    protected function initializeView(string $templateName)
+    {
+        $this->view = GeneralUtility::makeInstance(StandaloneView::class);
+        $this->view->setTemplate($templateName);
+        $this->view->setTemplateRootPaths(['EXT:documentation/Resources/Private/Templates/Help']);
+        $this->view->setPartialRootPaths(['EXT:documentation/Resources/Private/Partials']);
+        $this->view->setLayoutRootPaths(['EXT:documentation/Resources/Private/Layouts']);
+        $this->view->getRequest()->setControllerExtensionName('Documentation');
+        $this->view->assign('copyright', BackendUtility::TYPO3_copyRightNotice());
     }
 
     /**
@@ -92,14 +131,12 @@ class HelpController extends ActionController
     /**
      * Show a single manual
      *
-     * @param string $table
-     * @param string $field
+     * @param ServerRequestInterface $request
      */
-    public function detailAction($table = '', $field = '*')
+    public function detailAction(ServerRequestInterface $request)
     {
-        if (empty($table)) {
-            $this->forward('index');
-        }
+        $table = $request->getQueryParams()['table'] ?? $request->getParsedBody()['table'];
+        $field = $request->getQueryParams()['field'] ?? $request->getParsedBody()['field'] ?? '*';
 
         $mainKey = $table;
         $identifierParts = GeneralUtility::trimExplode('.', $field);
@@ -135,37 +172,26 @@ class HelpController extends ActionController
     /**
      * Registers the Icons into the docheader
      *
-     * @throws \InvalidArgumentException
+     * @param ServerRequestInterface $request
      */
-    protected function registerDocheaderButtons()
+    protected function registerDocheaderButtons(ServerRequestInterface $request)
     {
-        /** @var ButtonBar $buttonBar */
-        $buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar();
-        $currentRequest = $this->request;
-        $moduleName = $currentRequest->getPluginName();
-        $getVars = $this->request->getArguments();
-
-        $mayMakeShortcut = $this->getBackendUser()->mayMakeShortcut();
-
-        if ($mayMakeShortcut) {
-            $extensionName = $currentRequest->getControllerExtensionName();
-            if (count($getVars) === 0) {
-                $modulePrefix = strtolower('tx_' . $extensionName . '_' . $moduleName);
-                $getVars = ['id', 'route', $modulePrefix];
-            }
+        $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
+
+        if ($this->getBackendUser()->mayMakeShortcut()) {
             $shortcutButton = $buttonBar->makeShortcutButton()
-                ->setModuleName($moduleName)
-                ->setGetVariables($getVars);
+                ->setModuleName('help_cshmanual')
+                ->setGetVariables(['table', 'field', 'route']);
             $buttonBar->addButton($shortcutButton);
         }
 
-        if (isset($getVars['action']) && $getVars['action'] !== 'index') {
-            /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
-            $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
+        $action = $request->getQueryParams()['action'] ?? $request->getParsedBody()['action'] ?? 'index';
+        if ($action !== 'index') {
+            $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
             $backButton = $buttonBar->makeLinkButton()
                 ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:back'))
-                ->setIcon($this->view->getModuleTemplate()->getIconFactory()->getIcon('actions-view-go-up', Icon::SIZE_SMALL))
-                ->setHref((string)$uriBuilder->buildUriFromRoute($moduleName));
+                ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-view-go-up', Icon::SIZE_SMALL))
+                ->setHref((string)$uriBuilder->buildUriFromRoute('help_cshmanual'));
             $buttonBar->addButton($backButton);
         }
     }
@@ -175,7 +201,7 @@ class HelpController extends ActionController
      *
      * @return BackendUserAuthentication
      */
-    protected function getBackendUser()
+    protected function getBackendUser(): BackendUserAuthentication
     {
         return $GLOBALS['BE_USER'];
     }
@@ -185,7 +211,7 @@ class HelpController extends ActionController
      *
      * @return LanguageService
      */
-    protected function getLanguageService()
+    protected function getLanguageService(): LanguageService
     {
         return $GLOBALS['LANG'];
     }
index 51dec98..ee3e7a0 100644 (file)
@@ -39,11 +39,8 @@ class JavaScriptService
             $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
             $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
             $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/ContextHelp');
-            $pageRenderer->addInlineSetting('ContextHelp', 'moduleUrl', (string)$uriBuilder->buildUriFromRoute('help_DocumentationCshmanual', [
-                'tx_documentation_help_documentationcshmanual' => [
-                    'controller' => 'Help',
-                    'action' => 'detail'
-                ]
+            $pageRenderer->addInlineSetting('ContextHelp', 'moduleUrl', (string)$uriBuilder->buildUriFromRoute('help_cshmanual', [
+                'action' => 'detail'
             ]));
         }
     }
diff --git a/typo3/sysext/documentation/Classes/Utility/LanguageUtility.php b/typo3/sysext/documentation/Classes/Utility/LanguageUtility.php
deleted file mode 100644 (file)
index dc33d73..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-<?php
-namespace TYPO3\CMS\Documentation\Utility;
-
-/*
- * This file is part of the TYPO3 CMS project.
- *
- * It is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License, either version 2
- * of the License, or any later version.
- *
- * For the full copyright and license information, please read the
- * LICENSE.txt file that was distributed with this source code.
- *
- * The TYPO3 project - inspiring people to share!
- */
-
-/**
- * Utility for language selection.
- */
-class LanguageUtility implements \TYPO3\CMS\Core\SingletonInterface
-{
-    /**
-     * Returns the language from BE User settings.
-     *
-     * @return string language identifier 2 chars or default (English)
-     */
-    public function getDocumentationLanguage()
-    {
-        $backendLanguage = $GLOBALS['BE_USER']->uc['lang'] ?: 'default';
-        return $backendLanguage;
-    }
-}
index 89bd677..139e611 100644 (file)
@@ -1,3 +1,5 @@
+<html xmlns:be="http://typo3.org/ns/TYPO3/CMS/Backend/ViewHelpers">
+
 <h1>
        <f:translate key="LLL:EXT:documentation/Resources/Private/Language/locallang_view_help.xlf:manual_title" />
 </h1>
@@ -23,7 +25,9 @@
                                                                        <a href="#{module}">{module}</a>
                                                                </f:then>
                                                                <f:else>
-                                                                       <f:link.action action="detail" arguments="{table:module,field:'*'}">{title}</f:link.action>
+                                                                       <a href="{be:moduleLink(route:'help_cshmanual',arguments:{action:'detail', table:module,field:'*'})}">
+                                                                               {title}
+                                                                       </a>
                                                                </f:else>
                                                        </f:if>
                                                </li>
@@ -33,3 +37,5 @@
                </f:for>
        </ul>
 </f:if>
+
+</html>
\ No newline at end of file
index 718bad3..0af8979 100644 (file)
@@ -1,3 +1,5 @@
+<html xmlns:be="http://typo3.org/ns/TYPO3/CMS/Backend/ViewHelpers">
+
 <f:layout name="ContextSensitiveHelp" />
 
 <f:section name="docheader">
@@ -6,7 +8,8 @@
 <f:section name="content">
        <f:render partial="TableOfContents" arguments="{toc:toc,all:0}" />
 
-       <f:link.action action="all">
+       <a href="{be:moduleLink(route:'help_cshmanual',arguments:{action:'all'})}">
                <f:translate key="LLL:EXT:documentation/Resources/Private/Language/locallang_view_help.xlf:full_manual" />
-       </f:link.action>
+       </a>
 </f:section>
+</html>
\ No newline at end of file
index fc6133a..216045d 100644 (file)
@@ -17,15 +17,14 @@ defined('TYPO3_MODE') or die();
     ]
 );
 
-\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerModule(
-    'TYPO3.CMS.Documentation',
+\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addModule(
     'help',
     'cshmanual',
     'top',
+    '',
     [
-        'Help' => 'index,all,detail',
-    ],
-    [
+        'routeTarget' => \TYPO3\CMS\Documentation\Controller\HelpController::class . '::handleRequest',
+        'name' => 'help_cshmanual',
         'access' => 'user,group',
         'icon' => 'EXT:documentation/Resources/Public/Icons/module-cshmanual.svg',
         'labels' => 'LLL:EXT:documentation/Resources/Private/Language/locallang_mod_help_cshmanual.xlf',