[TASK] Use ModuleTemplate API for ext:beuser 70/43870/8
authorMichael Oehlhof <typo3@oehlhof.de>
Tue, 6 Oct 2015 19:11:51 +0000 (21:11 +0200)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Tue, 13 Oct 2015 16:38:27 +0000 (18:38 +0200)
Resolves: #70360
Releases: master
Change-Id: Iabdc4d95372acebfc6357430bc6d1357493dc93d
Reviewed-on: http://review.typo3.org/43870
Reviewed-by: Daniel Goerz <ervaude@gmail.com>
Tested-by: Daniel Goerz <ervaude@gmail.com>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
typo3/sysext/beuser/Classes/Controller/BackendUserActionController.php [new file with mode: 0644]
typo3/sysext/beuser/Classes/Controller/BackendUserController.php
typo3/sysext/beuser/Classes/Controller/BackendUserGroupController.php
typo3/sysext/beuser/Resources/Private/Layouts/Default.html
typo3/sysext/beuser/Resources/Private/Layouts/Permission.html
typo3/sysext/beuser/Resources/Private/Templates/BackendUser/Compare.html
typo3/sysext/beuser/Resources/Private/Templates/BackendUser/Index.html
typo3/sysext/beuser/Resources/Private/Templates/BackendUser/Online.html
typo3/sysext/beuser/Resources/Private/Templates/BackendUserGroup/Index.html
typo3/sysext/beuser/Resources/Private/Templates/Permission/Edit.html
typo3/sysext/beuser/Resources/Private/Templates/Permission/Index.html

diff --git a/typo3/sysext/beuser/Classes/Controller/BackendUserActionController.php b/typo3/sysext/beuser/Classes/Controller/BackendUserActionController.php
new file mode 100644 (file)
index 0000000..650e9bb
--- /dev/null
@@ -0,0 +1,207 @@
+<?php
+namespace TYPO3\CMS\Beuser\Controller;
+
+/*
+ * 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!
+ */
+
+use TYPO3\CMS\Backend\Template\Components\ButtonBar;
+use TYPO3\CMS\Backend\View\BackendTemplateView;
+use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
+use TYPO3\CMS\Core\Imaging\Icon;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
+use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
+use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
+use TYPO3\CMS\Lang\LanguageService;
+
+/**
+ * Backend module user/group action controller
+ */
+class BackendUserActionController extends ActionController
+{
+    /**
+     * Backend Template Container
+     *
+     * @var string
+     */
+    protected $defaultViewObjectName = BackendTemplateView::class;
+
+    /**
+     * BackendTemplateContainer
+     *
+     * @var BackendTemplateView
+     */
+    protected $view;
+
+    /**
+     * Set up the doc header properly here
+     *
+     * @param ViewInterface $view
+     * @return void
+     */
+    protected function initializeView(ViewInterface $view)
+    {
+        /** @var BackendTemplateView $view */
+        parent::initializeView($view);
+        if ($this->actionMethodName == 'indexAction'
+            || $this->actionMethodName == 'onlineAction'
+            || $this->actionMethodName == 'compareAction') {
+            $this->generateMenu();
+            $this->registerDocheaderButtons();
+        }
+    }
+
+    /**
+     * Generates the action menu
+     *
+     * @return void
+     */
+    protected function generateMenu()
+    {
+        $menuItems = [
+            'index' => [
+                'controller' => 'BackendUser',
+                'action' => 'index',
+                'label' => $this->getLanguageService()->sL('LLL:EXT:beuser/Resources/Private/Language/locallang.xml:backendUsers')
+            ],
+            'pages' => [
+                'controller' => 'BackendUserGroup',
+                'action' => 'index',
+                'label' => $this->getLanguageService()->sL('LLL:EXT:beuser/Resources/Private/Language/locallang.xml:backendUserGroupsMenu')
+            ],
+            'online' => [
+                'controller' => 'BackendUser',
+                'action' => 'online',
+                'label' => $this->getLanguageService()->sL('LLL:EXT:beuser/Resources/Private/Language/locallang.xml:onlineUsers')
+            ]
+        ];
+        $uriBuilder = $this->objectManager->get(UriBuilder::class);
+        $uriBuilder->setRequest($this->request);
+
+        $menu = $this->view->getModuleTemplate()->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
+        $menu->setIdentifier('BackendUserModuleMenu');
+
+        foreach ($menuItems as  $menuItemConfig) {
+            if ($this->request->getControllerName() === $menuItemConfig['controller']) {
+                $isActive = $this->request->getControllerActionName() === $menuItemConfig['action'] ? true : false;
+            } else {
+                $isActive = false;
+            }
+            $menuItem = $menu->makeMenuItem()
+                ->setTitle($menuItemConfig['label'])
+                ->setHref($this->getHref($menuItemConfig['controller'], $menuItemConfig['action']))
+                ->setActive($isActive);
+            $menu->addMenuItem($menuItem);
+        }
+
+        $this->view->getModuleTemplate()->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu);
+    }
+
+    /**
+     * Registers the Icons into the docheader
+     *
+     * @return void
+     * @throws \InvalidArgumentException
+     */
+    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 = array('id', 'M', $modulePrefix);
+        }
+        $shortcutButton = $buttonBar->makeShortcutButton()
+            ->setModuleName($moduleName)
+            ->setGetVariables($getVars);
+        $buttonBar->addButton($shortcutButton);
+        if ($this->request->getControllerName() === 'BackendUser') {
+            if ($this->request->getControllerActionName() === 'index') {
+                $returnUrl = rawurlencode(BackendUtility::getModuleUrl('system_BeuserTxBeuser'));
+                $parameters = GeneralUtility::explodeUrl2Array('edit[be_users][0]=new&returnUrl=' . $returnUrl);
+                $addUserLink = BackendUtility::getModuleUrl('record_edit', $parameters);
+                $title = $this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:newRecordGeneral', true);
+                $icon = $this->view->getModuleTemplate()->getIconFactory()->getIcon('actions-document-new', Icon::SIZE_SMALL);
+                $addUserButton = $buttonBar->makeLinkButton()
+                    ->setHref($addUserLink)
+                    ->setTitle($title)
+                    ->setIcon($icon);
+                $buttonBar->addButton($addUserButton, ButtonBar::BUTTON_POSITION_LEFT);
+            }
+            if ($this->request->getControllerActionName() === 'compare') {
+                $addUserLink = BackendUtility::getModuleUrl('system_BeuserTxBeuser');
+                $title = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.goBack', true);
+                $icon = $this->view->getModuleTemplate()->getIconFactory()->getIcon('actions-view-go-back', Icon::SIZE_SMALL);
+                $addUserButton = $buttonBar->makeLinkButton()
+                    ->setHref($addUserLink)
+                    ->setTitle($title)
+                    ->setIcon($icon);
+                $buttonBar->addButton($addUserButton, ButtonBar::BUTTON_POSITION_LEFT);
+            }
+        }
+        if ($this->request->getControllerName() === 'BackendUserGroup') {
+            $returnUrl = rawurlencode(BackendUtility::getModuleUrl('system_BeuserTxBeuser', array(
+                'tx_beuser_system_beusertxbeuser' => array(
+                    'action' => 'index',
+                    'controller' => 'BackendUserGroup'
+                )
+            )));
+            $parameters = GeneralUtility::explodeUrl2Array('edit[be_groups][0]=new&returnUrl=' . $returnUrl);
+            $addUserLink = BackendUtility::getModuleUrl('record_edit', $parameters);
+            $title = $this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:newRecordGeneral', true);
+            $icon = $this->view->getModuleTemplate()->getIconFactory()->getIcon('actions-document-new', Icon::SIZE_SMALL);
+            $addUserGroupButton = $buttonBar->makeLinkButton()
+                ->setHref($addUserLink)
+                ->setTitle($title)
+                ->setIcon($icon);
+            $buttonBar->addButton($addUserGroupButton, ButtonBar::BUTTON_POSITION_LEFT);
+        }
+    }
+
+    /**
+     * Creates te URI for a backend action
+     *
+     * @param string $controller
+     * @param string $action
+     * @param array $parameters
+     * @return string
+     */
+    protected function getHref($controller, $action, $parameters = [])
+    {
+        $uriBuilder = $this->objectManager->get(UriBuilder::class);
+        $uriBuilder->setRequest($this->request);
+        return $uriBuilder->reset()->uriFor($action, $parameters, $controller);
+    }
+
+    /**
+     * @return BackendUserAuthentication
+     */
+    protected function getBackendUserAuthentication()
+    {
+        return $GLOBALS['BE_USER'];
+    }
+
+    /**
+     * @return LanguageService
+     */
+    protected function getLanguageService()
+    {
+        return $GLOBALS['LANG'];
+    }
+}
\ No newline at end of file
index f711cfe..aeed2cb 100644 (file)
@@ -15,12 +15,15 @@ namespace TYPO3\CMS\Beuser\Controller;
  */
 
 use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
+use TYPO3\CMS\Core\Database\DatabaseConnection;
 use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
+use TYPO3\CMS\Lang\LanguageService;
 
 /**
  * Backend module user administration controller
  */
-class BackendUserController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
+class BackendUserController extends BackendUserActionController
 {
     /**
      * @var \TYPO3\CMS\Beuser\Domain\Model\ModuleData
@@ -176,7 +179,7 @@ class BackendUserController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionCont
         $this->view->assign('dateFormat', $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']);
         $this->view->assign('timeFormat', $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm']);
         $this->view->assign('onlineUsersAndSessions', $onlineUsersAndSessions);
-        $this->view->assign('currentSessionId', $GLOBALS['BE_USER']->user['ses_id']);
+        $this->view->assign('currentSessionId', $this->getBackendUserAuthentication()->user['ses_id']);
     }
 
     /**
@@ -228,11 +231,11 @@ class BackendUserController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionCont
      */
     protected function terminateBackendUserSessionAction(\TYPO3\CMS\Beuser\Domain\Model\BackendUser $backendUser, $sessionId)
     {
-        $GLOBALS['TYPO3_DB']->exec_DELETEquery(
+        $this->getDatabaseConnection()->exec_DELETEquery(
             'be_sessions',
-            'ses_userid = "' . (int)$backendUser->getUid() . '" AND ses_id = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($sessionId, 'be_sessions') . ' LIMIT 1'
+            'ses_userid = "' . (int)$backendUser->getUid() . '" AND ses_id = ' . $this->getDatabaseConnection()->fullQuoteStr($sessionId, 'be_sessions') . ' LIMIT 1'
         );
-        if ($GLOBALS['TYPO3_DB']->sql_affected_rows() == 1) {
+        if ($this->getDatabaseConnection()->sql_affected_rows() == 1) {
             $this->addFlashMessage(LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:terminateSessionSuccess', 'beuser'));
         }
         $this->forward('online');
@@ -247,19 +250,19 @@ class BackendUserController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionCont
     protected function switchUser($switchUser)
     {
         $targetUser = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord('be_users', $switchUser);
-        if (is_array($targetUser) && $GLOBALS['BE_USER']->isAdmin()) {
+        if (is_array($targetUser) && $this->getBackendUserAuthentication()->isAdmin()) {
             $updateData['ses_userid'] = (int)$targetUser['uid'];
-            $updateData['ses_backuserid'] = (int)$GLOBALS['BE_USER']->user['uid'];
+            $updateData['ses_backuserid'] = (int)$this->getBackendUserAuthentication()->user['uid'];
 
             // Set backend user listing module as starting module for switchback
-            $GLOBALS['BE_USER']->uc['startModuleOnFirstLogin'] = 'system_BeuserTxBeuser';
-            $GLOBALS['BE_USER']->writeUC();
+            $this->getBackendUserAuthentication()->uc['startModuleOnFirstLogin'] = 'system_BeuserTxBeuser';
+            $this->getBackendUserAuthentication()->writeUC();
 
-            $whereClause = 'ses_id=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($GLOBALS['BE_USER']->id, 'be_sessions');
-            $whereClause .= ' AND ses_name=' . $GLOBALS['TYPO3_DB']->fullQuoteStr(\TYPO3\CMS\Core\Authentication\BackendUserAuthentication::getCookieName(), 'be_sessions');
-            $whereClause .= ' AND ses_userid=' . (int)$GLOBALS['BE_USER']->user['uid'];
+            $whereClause = 'ses_id=' . $this->getDatabaseConnection()->fullQuoteStr($this->getBackendUserAuthentication()->id, 'be_sessions');
+            $whereClause .= ' AND ses_name=' . $this->getDatabaseConnection()->fullQuoteStr(\TYPO3\CMS\Core\Authentication\BackendUserAuthentication::getCookieName(), 'be_sessions');
+            $whereClause .= ' AND ses_userid=' . (int)$this->getBackendUserAuthentication()->user['uid'];
 
-            $GLOBALS['TYPO3_DB']->exec_UPDATEquery(
+            $this->getDatabaseConnection()->exec_UPDATEquery(
                 'be_sessions',
                 $whereClause,
                 $updateData
@@ -269,4 +272,28 @@ class BackendUserController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionCont
             \TYPO3\CMS\Core\Utility\HttpUtility::redirect($redirectUrl);
         }
     }
+
+    /**
+     * @return DatabaseConnection
+     */
+    protected function getDatabaseConnection()
+    {
+        return $GLOBALS['TYPO3_DB'];
+    }
+
+    /**
+     * @return BackendUserAuthentication
+     */
+    protected function getBackendUserAuthentication()
+    {
+        return $GLOBALS['BE_USER'];
+    }
+
+    /**
+     * @return LanguageService
+     */
+    protected function getLanguageService()
+    {
+        return $GLOBALS['LANG'];
+    }
 }
index d83967b..0edda49 100644 (file)
@@ -19,7 +19,7 @@ use TYPO3\CMS\Backend\Utility\BackendUtility;
 /**
  * Backend module user group administration controller
  */
-class BackendUserGroupController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
+class BackendUserGroupController extends BackendUserActionController
 {
     /**
      * @var \TYPO3\CMS\Beuser\Domain\Repository\BackendUserGroupRepository
@@ -59,12 +59,6 @@ class BackendUserGroupController extends \TYPO3\CMS\Extbase\Mvc\Controller\Actio
      */
     public function indexAction()
     {
-        $this->view->assign('returnUrl', rawurlencode(BackendUtility::getModuleUrl('system_BeuserTxBeuser', array(
-            'tx_beuser_system_beusertxbeuser' => array(
-                'action' => 'index',
-                'controller' => 'BackendUserGroup'
-            )
-        ))));
         $this->view->assign('backendUserGroups', $this->backendUserGroupRepository->findAll());
     }
 }
index d789bae..4389549 100644 (file)
@@ -1,35 +1,7 @@
-<f:be.container includeRequireJsModules="{0: 'TYPO3/CMS/Backend/Modal', 1: 'TYPO3/CMS/Beuser/BackendUserListing'}">
-       <div class="typo3-fullDoc">
-               <div id="typo3-docheader">
-                       <div class="typo3-docheader-functions">
-                               <div class="left">
-                                       <f:be.buttons.csh />
-                                       <f:be.menus.actionMenu>
-                                               <f:be.menus.actionMenuItem label="{f:translate(key: 'backendUsers')}" controller="BackendUser" action="index" />
-                                               <f:be.menus.actionMenuItem label="{f:translate(key: 'backendUserGroupsMenu')}" controller="BackendUserGroup" action="index" />
-                                               <f:be.menus.actionMenuItem label="{f:translate(key: 'onlineUsers')}" controller="BackendUser" action="online" />
-                                       </f:be.menus.actionMenu>
-                               </div>
-                               <div class="right">
-                               </div>
-                       </div>
-                       <div class="typo3-docheader-buttons">
-                               <div class="left">
-                                       <f:render section="iconButtons" />
-                               </div>
-                               <div class="right">
-                                       <f:be.buttons.shortcut />
-                               </div>
-                       </div>
-               </div>
-               <div id="typo3-docbody">
-                       <div id="typo3-inner-docbody">
-                               <f:render section="headline" />
+<f:be.pageRenderer />
 
-                               <f:flashMessages />
+<f:render section="headline" />
 
-                               <f:render section="content" />
-                       </div>
-               </div>
-       </div>
-</f:be.container>
+<f:flashMessages />
+
+<f:render section="content" />
index c5482df..bc8b5eb 100644 (file)
@@ -1,40 +1,15 @@
-<f:be.container
-       includeRequireJsModules="{0: 'TYPO3/CMS/Beuser/Permissions'}"
-       loadExtJsTheme="0"
-       loadJQuery="1"
->
-       <div class="typo3-fullDoc">
-               <div id="typo3-docheader">
-                       <div class="typo3-docheader-functions">
-                               <div class="left"></div>
-                               <div class="right"></div>
-                       </div>
-                       <div class="typo3-docheader-buttons">
-                               <div class="left">
-                                       <f:render section="iconButtons" />
-                               </div>
-                               <div class="right">
-                                       <f:be.buttons.shortcut />
-                               </div>
-                       </div>
-               </div>
-               <div id="typo3-docbody">
-                       <div id="typo3-inner-docbody">
-                               <f:render section="headline" />
+<f:be.pageRenderer />
+<f:render section="headline" />
 
-                               <f:flashMessages as="flashMessages">
-                                       <ul class="typo3-flashMessages">
-                                               <f:for each="{flashMessages}" as="flashMessage">
-                                                       <li class="alert {flashMessage.class}">
-                                                               <h4><f:translate id="{flashMessage.title}" extensionName="beuser" /></h4>
-                                                               <f:translate id="{flashMessage.message}" extensionName="beuser" />
-                                                       </li>
-                                               </f:for>
-                                       </ul>
-                               </f:flashMessages>
+<f:flashMessages as="flashMessages">
+       <ul class="typo3-flashMessages">
+               <f:for each="{flashMessages}" as="flashMessage">
+                       <li class="alert {flashMessage.class}">
+                               <h4><f:translate id="{flashMessage.title}" extensionName="beuser" /></h4>
+                               <f:translate id="{flashMessage.message}" extensionName="beuser" />
+                       </li>
+               </f:for>
+       </ul>
+</f:flashMessages>
 
-                               <f:render section="content" />
-                       </div>
-               </div>
-       </div>
-</f:be.container>
+<f:render section="content" />
index 3c12022..d7d383c 100644 (file)
@@ -4,10 +4,6 @@
 
 <f:layout name="Default" />
 
-<f:section name="iconButtons">
-       <f:link.action action="index"><core:icon identifier="actions-view-go-back" /></f:link.action>
-</f:section>
-
 <f:section name="headline">
        <h1><f:translate key="compareBackendUsers">Compare backend users</f:translate></h1>
 </f:section>
index fe5d902..2801407 100644 (file)
@@ -4,10 +4,6 @@
 
 <f:layout name="Default" />
 
-<f:section name="iconButtons">
-       <a href="{bu:editRecord(parameters: 'edit[be_users][0]=new&returnUrl={returnUrl}')}"><core:icon identifier="actions-document-new" /></a>
-</f:section>
-
 <f:section name="headline">
        <h1><f:translate key="backendUserListing" /></h1>
 </f:section>
index 3ad4041..0403ca1 100644 (file)
@@ -2,9 +2,6 @@
 
 <f:layout name="Default" />
 
-<f:section name="iconButtons">
-</f:section>
-
 <f:section name="headline">
        <h1><f:translate key="onlineUsers" /></h1>
 </f:section>
index e1448e1..93f513f 100644 (file)
@@ -4,10 +4,6 @@
 
 <f:layout name="Default" />
 
-<f:section name="iconButtons">
-       <a href="{bu:editRecord(parameters: 'edit[be_groups][0]=new&returnUrl={returnUrl}')}"><core:icon identifier="actions-document-new" /></a>
-</f:section>
-
 <f:section name="headline">
        <h1><f:translate key="backendUserGroupListing" /></h1>
 </f:section>
index 294bf89..af3d6fc 100644 (file)
@@ -3,15 +3,6 @@
 
 <f:layout name="Permission" />
 
-<f:section name="iconButtons">
-       <a href="{f:uri.action(action:'index')}">
-               <core:icon identifier="actions-view-go-back" />
-       </a>
-       <a href="#" onclick="{previewUrl}" title="{f:translate(key: 'LLL:EXT:lang/locallang_core.xlf:labels.showPage')}">
-               <core:icon identifier="actions-document-view" />
-       </a>
-</f:section>
-
 <f:section name="headline">
        <h1>
                <f:translate key="LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:permissions" />:
index 9545d49..ddfdd15 100644 (file)
@@ -4,12 +4,6 @@
 
 <f:layout name="Permission" />
 
-<f:section name="iconButtons">
-       <a href="#" onclick="{previewUrl}" title="{f:translate(key: 'LLL:EXT:lang/locallang_core.xlf:labels.showPage')}">
-               <core:icon identifier="actions-document-view" />
-       </a>
-</f:section>
-
 <f:section name="headline">
        <h1><f:translate key="LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:permissions" /></h1>
 </f:section>