[TASK] Remove usage of extbase from recycler module 63/56363/4
authorGeorg Ringer <georg.ringer@gmail.com>
Mon, 19 Mar 2018 12:57:57 +0000 (13:57 +0100)
committerBenni Mack <benni@typo3.org>
Tue, 20 Mar 2018 04:59:24 +0000 (05:59 +0100)
Simplify the recycler module by reducing the overhead of
extbase.

Resolves: #84477
Releases: master
Change-Id: I79a74686a54aa0f5fcee06c39e046f9e35fee9d1
Reviewed-on: https://review.typo3.org/56363
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: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/recycler/Classes/Controller/RecyclerModuleController.php
typo3/sysext/recycler/Resources/Private/Templates/RecyclerModule/NoAccess.html [deleted file]
typo3/sysext/recycler/ext_tables.php

index 06a003e..2fa266a 100644 (file)
@@ -14,28 +14,25 @@ namespace TYPO3\CMS\Recycler\Controller;
  * The TYPO3 project - inspiring people to share!
  */
 
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
 use TYPO3\CMS\Backend\Template\Components\ButtonBar;
-use TYPO3\CMS\Backend\View\BackendTemplateView;
+use TYPO3\CMS\Backend\Template\ModuleTemplate;
+use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
+use TYPO3\CMS\Core\Http\HtmlResponse;
+use TYPO3\CMS\Core\Http\NormalizedParams;
 use TYPO3\CMS\Core\Imaging\Icon;
+use TYPO3\CMS\Core\Localization\LanguageService;
 use TYPO3\CMS\Core\Type\Bitmask\Permission;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
-use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
-use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
+use TYPO3\CMS\Fluid\View\StandaloneView;
 
 /**
- * Module 'Recycler' for the 'recycler' extension.
+ * Backend Module for the 'recycler' extension.
  */
-class RecyclerModuleController extends ActionController
+class RecyclerModuleController
 {
-    /**
-     * @var string
-     */
-    protected $relativePath;
-
-    /**
-     * @var string
-     */
-    public $perms_clause;
 
     /**
      * @var array
@@ -63,27 +60,28 @@ class RecyclerModuleController extends ActionController
     protected $id;
 
     /**
-     * @var BackendTemplateView
+     * @var StandaloneView
      */
     protected $view;
 
     /**
-     * BackendTemplateView Container
-     *
-     * @var BackendTemplateView
+     * @var ModuleTemplate
      */
-    protected $defaultViewObjectName = BackendTemplateView::class;
+    protected $moduleTemplate;
 
     /**
-     * Initializes the Module
+     * Injects the request object for the current request, and renders correct action
+     *
+     * @param ServerRequestInterface $request the current request
+     * @return ResponseInterface the response with the content
      */
-    public function initializeAction()
+    public function handleRequest(ServerRequestInterface $request): ResponseInterface
     {
-        $this->id = (int)GeneralUtility::_GP('id');
+        $this->id = (int)($request->getQueryParams()['id'] ?? $request->getParsedBody()['id'] ?? 0);
         $backendUser = $this->getBackendUser();
-        $this->perms_clause = $backendUser->getPagePermsClause(Permission::PAGE_SHOW);
-        $this->pageRecord = \TYPO3\CMS\Backend\Utility\BackendUtility::readPageAccess($this->id, $this->perms_clause);
+        $this->pageRecord = BackendUtility::readPageAccess($this->id, $backendUser->getPagePermsClause(Permission::PAGE_SHOW));
         $this->isAccessibleForCurrentUser = $this->id && is_array($this->pageRecord) || !$this->id && $this->getBackendUser()->isAdmin();
+        $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
 
         // don't access in workspace
         if ($backendUser->workspace !== 0) {
@@ -101,35 +99,47 @@ class RecyclerModuleController extends ActionController
         if (isset($modTS['properties']['recordsPageLimit']) && (int)$modTS['properties']['recordsPageLimit'] > 0) {
             $this->recordsPageLimit = (int)$modTS['properties']['recordsPageLimit'];
         }
+
+        $action = 'index';
+        $this->initializeView($action);
+
+        $result = call_user_func_array([$this, $action . 'Action'], [$request]);
+        if ($result instanceof ResponseInterface) {
+            return $result;
+        }
+
+        $this->registerDocheaderButtons();
+
+        $this->moduleTemplate->setContent($this->view->render());
+        return new HtmlResponse($this->moduleTemplate->renderContent());
     }
 
     /**
-     * Initialize the view
-     *
-     * @param ViewInterface $view The view
+     * @param string $templateName
      */
-    public function initializeView(ViewInterface $view)
+    protected function initializeView(string $templateName)
     {
-        /** @var BackendTemplateView $view */
-        parent::initializeView($view);
-        $this->registerDocheaderButtons();
-        $this->view->getModuleTemplate()->setFlashMessageQueue($this->controllerContext->getFlashMessageQueue());
+        $this->view = GeneralUtility::makeInstance(StandaloneView::class);
+        $this->view->setTemplate($templateName);
+        $this->view->setTemplateRootPaths(['EXT:recycler/Resources/Private/Templates/RecyclerModule']);
+        $this->view->setPartialRootPaths(['EXT:recycler/Resources/Private/Partials']);
+        $this->view->setLayoutRootPaths(['EXT:recycler/Resources/Private/Layouts']);
+        $this->view->getRequest()->setControllerExtensionName('Recycler');
     }
 
     /**
      * Renders the content of the module.
+     *
+     * @param ServerRequestInterface $request
      */
-    public function indexAction()
+    public function indexAction(ServerRequestInterface $request)
     {
-        // Integrate dynamic JavaScript such as configuration or lables:
-        $jsConfiguration = $this->getJavaScriptConfiguration();
-        $this->view->getModuleTemplate()->getPageRenderer()->addInlineSettingArray('Recycler', $jsConfiguration);
-        $this->view->getModuleTemplate()->getPageRenderer()->addInlineLanguageLabelFile('EXT:recycler/Resources/Private/Language/locallang.xlf');
+        $this->moduleTemplate->getPageRenderer()->addInlineSettingArray('Recycler', $this->getJavaScriptConfiguration($request->getAttribute('normalizedParams')));
+        $this->moduleTemplate->getPageRenderer()->addInlineLanguageLabelFile('EXT:recycler/Resources/Private/Language/locallang.xlf');
         if ($this->isAccessibleForCurrentUser) {
-            $this->view->getModuleTemplate()->getDocHeaderComponent()->setMetaInformation($this->pageRecord);
+            $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($this->pageRecord);
         }
 
-        $this->view->assign('title', $this->getLanguageService()->getLL('title'));
         $this->view->assign('allowDelete', $this->allowDelete);
     }
 
@@ -140,48 +150,39 @@ class RecyclerModuleController extends ActionController
      */
     protected function registerDocheaderButtons()
     {
-        /** @var ButtonBar $buttonBar */
-        $buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar();
-        $currentRequest = $this->request;
-        $moduleName = $currentRequest->getPluginName();
-        $getVars = $this->request->getArguments();
-
-        $extensionName = $currentRequest->getControllerExtensionName();
-        if (count($getVars) === 0) {
-            $modulePrefix = strtolower('tx_' . $extensionName . '_' . $moduleName);
-            $getVars = ['id', 'route', $modulePrefix];
-        }
+        $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
+
         $shortcutButton = $buttonBar->makeShortcutButton()
-            ->setModuleName($moduleName)
-            ->setGetVariables($getVars);
+            ->setModuleName('web_recycler')
+            ->setGetVariables(['id', 'route']);
         $buttonBar->addButton($shortcutButton);
 
         $reloadButton = $buttonBar->makeLinkButton()
             ->setHref('#')
             ->setDataAttributes(['action' => 'reload'])
             ->setTitle($this->getLanguageService()->sL('LLL:EXT:recycler/Resources/Private/Language/locallang.xlf:button.reload'))
-            ->setIcon($this->view->getModuleTemplate()->getIconFactory()->getIcon('actions-refresh', Icon::SIZE_SMALL));
+            ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-refresh', Icon::SIZE_SMALL));
         $buttonBar->addButton($reloadButton, ButtonBar::BUTTON_POSITION_RIGHT);
     }
 
     /**
      * Gets the JavaScript configuration.
      *
+     * @param NormalizedParams $normalizedParams
      * @return array The JavaScript configuration
      */
-    protected function getJavaScriptConfiguration()
+    protected function getJavaScriptConfiguration(NormalizedParams $normalizedParams): array
     {
-        $configuration = [
+        return [
             'pagingSize' => $this->recordsPageLimit,
-            'showDepthMenu' => 1,
-            'startUid' => (int)GeneralUtility::_GP('id'),
-            'isSSL' => GeneralUtility::getIndpEnv('TYPO3_SSL'),
+            'showDepthMenu' => true,
+            'startUid' => $this->id,
+            'isSSL' => $normalizedParams->isHttps(),
             'deleteDisable' => !$this->allowDelete,
             'depthSelection' => $this->getDataFromSession('depthSelection', 0),
             'tableSelection' => $this->getDataFromSession('tableSelection', ''),
             'States' => $this->getBackendUser()->uc['moduleData']['web_recycler']['States']
         ];
-        return $configuration;
     }
 
     /**
@@ -205,29 +206,19 @@ class RecyclerModuleController extends ActionController
     /**
      * Returns the current BE user.
      *
-     * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
+     * @return BackendUserAuthentication
      */
-    protected function getBackendUser()
+    protected function getBackendUser(): BackendUserAuthentication
     {
         return $GLOBALS['BE_USER'];
     }
 
     /**
-     * Returns an instance of DocumentTemplate
-     *
-     * @return \TYPO3\CMS\Backend\Template\DocumentTemplate
-     */
-    protected function getDocumentTemplate()
-    {
-        return $GLOBALS['TBE_TEMPLATE'];
-    }
-
-    /**
      * Returns an instance of LanguageService
      *
-     * @return \TYPO3\CMS\Core\Localization\LanguageService
+     * @return LanguageService
      */
-    protected function getLanguageService()
+    protected function getLanguageService(): LanguageService
     {
         return $GLOBALS['LANG'];
     }
diff --git a/typo3/sysext/recycler/Resources/Private/Templates/RecyclerModule/NoAccess.html b/typo3/sysext/recycler/Resources/Private/Templates/RecyclerModule/NoAccess.html
deleted file mode 100644 (file)
index 920e5a5..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-<f:layout name="Default" />
-
-<f:section name="iconButtons">
-</f:section>
-
-<f:section name="content">
-       --No Access--
-</f:section>
\ No newline at end of file
index d4d202d..664d7b0 100644 (file)
@@ -1,16 +1,16 @@
 <?php
 defined('TYPO3_MODE') or die();
 
-\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerModule(
-    'TYPO3.CMS.Recycler',
+\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addModule(
     'web',
-    'Recycler',
+    // Legacy name, as this module was previously a Extbase controller. Keeping the name allows to keep the sys_be_shortcut functionality alive
+    'RecyclerRecycler',
     '',
+    null,
     [
-        'RecyclerModule' => 'index',
-    ],
-    [
+        'routeTarget' => \TYPO3\CMS\Recycler\Controller\RecyclerModuleController::class . '::handleRequest',
         'access' => 'user,group',
+        'name' => 'web_RecyclerRecycler',
         'icon' => 'EXT:recycler/Resources/Public/Icons/module-recycler.svg',
         'labels' => 'LLL:EXT:recycler/Resources/Private/Language/locallang_mod.xlf',
     ]