From 0a6320c1667ccdc54dd5be98ad347248343a25e9 Mon Sep 17 00:00:00 2001 From: Benjamin Mack <benni@typo3.org> Date: Sat, 22 Nov 2014 19:44:51 +0100 Subject: [PATCH] [TASK] Cleanup BackendController.php (part 1) The backend controller has some leftover code. First, the main output is moved to a standalone fluid view. Additionally, the UserMenu.js is not needed anymore, as Bootstrap Dropdown is taking care of its logic. Some minor code logic cleanup is also added, as well as a @todo note. Releases: master Resolves: #63145 Change-Id: I9323a036a160561a165ede22a3e707bbe4a540ae Reviewed-on: http://review.typo3.org/34469 Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de> Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de> Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl> Tested-by: Wouter Wolters <typo3@wouterwolters.nl> --- .../Classes/Controller/BackendController.php | 52 +++++++---------- .../Private/Templates/Backend/Main.html | 11 ++++ .../Public/JavaScript/Toolbar/UserMenu.js | 57 ------------------- 3 files changed, 33 insertions(+), 87 deletions(-) create mode 100644 typo3/sysext/backend/Resources/Private/Templates/Backend/Main.html delete mode 100644 typo3/sysext/backend/Resources/Public/JavaScript/Toolbar/UserMenu.js diff --git a/typo3/sysext/backend/Classes/Controller/BackendController.php b/typo3/sysext/backend/Classes/Controller/BackendController.php index 31644ddac65f..0b361f430137 100644 --- a/typo3/sysext/backend/Classes/Controller/BackendController.php +++ b/typo3/sysext/backend/Classes/Controller/BackendController.php @@ -136,15 +136,9 @@ class BackendController { // Add default BE css $this->pageRenderer->addCssLibrary('contrib/normalize/normalize.css', 'stylesheet', 'all', '', TRUE, TRUE); - // load the toolbar items - $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Toolbar/UserMenu'); - $this->css = ''; $this->initializeToolbarItems(); - $this->menuWidth = $this->menuWidthDefault; - if (isset($GLOBALS['TBE_STYLES']['dims']['leftMenuFrameW']) && (int)$GLOBALS['TBE_STYLES']['dims']['leftMenuFrameW'] != (int)$this->menuWidth) { - $this->menuWidth = (int)$GLOBALS['TBE_STYLES']['dims']['leftMenuFrameW']; - } + $this->menuWidth = isset($GLOBALS['TBE_STYLES']['dims']['leftMenuFrameW']) ? (int)$GLOBALS['TBE_STYLES']['dims']['leftMenuFrameW'] : $this->menuWidthDefault; $this->executeHook('constructPostProcess'); } @@ -192,21 +186,11 @@ class BackendController { $this->executeHook('renderPreProcess'); // Prepare the scaffolding, at this point extension may still add javascript and css - $logo = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\View\LogoView::class); - - // Create backend scaffolding - $backendScaffolding = ' - <div class="navbar navbar-inverse x-hide-display" role="navigation" id="typo3-top-container"> - <div class="container-fluid"> - <div class="navbar-header" id="typo3-logo">' . - $logo->render() . - '</div> - <div id="typo3-top">' . - $this->renderToolbar() . - '</div> - </div> - </div>' . - $this->generateModuleMenu(); + $view = $this->getFluidTemplateObject('EXT:backend/Resources/Private/Templates/Backend/Main.html'); + // @todo: kick logo view class and move all logic to Fluid + $view->assign('logo', GeneralUtility::makeInstance(\TYPO3\CMS\Backend\View\LogoView::class)->render()); + $view->assign('moduleMenu', $this->generateModuleMenu()); + $view->assign('toolbar', $this->renderToolbar()); /****************************************************** * Now put the complete backend document together @@ -252,9 +236,8 @@ class BackendController { $this->pageRenderer->addExtOnReadyCode($extOnReadyCode); // Set document title: $title = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] ? $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] . ' [TYPO3 CMS ' . TYPO3_version . ']' : 'TYPO3 CMS ' . TYPO3_version; - $this->content = $backendScaffolding; // Renders the module page - $this->content = $GLOBALS['TBE_TEMPLATE']->render($title, $this->content); + $this->content = $GLOBALS['TBE_TEMPLATE']->render($title, $view->render()); $hookConfiguration = array('content' => &$this->content); $this->executeHook('renderPostProcess', $hookConfiguration); echo $this->content; @@ -315,7 +298,6 @@ class BackendController { */ protected function renderToolbar() { $toolbar = array(); - $toolbar[] = '<ul class="nav navbar-nav navbar-right typo3-top-toolbar" id="typo3-toolbar">'; foreach ($this->toolbarItems as $toolbarItem) { /** @var \TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface $toolbarItem */ if ($toolbarItem->checkAccess()) { @@ -362,8 +344,6 @@ class BackendController { $toolbar[] = '</li>'; } } - $toolbar[] = '</ul>'; - return implode(LF, $toolbar); } @@ -758,9 +738,7 @@ class BackendController { // get all modules except the user modules for the side menu $moduleStorage = $this->backendModuleRepository->loadAllowedModules(array('user', 'help')); - /** @var $view \TYPO3\CMS\Fluid\View\StandaloneView */ - $view = GeneralUtility::makeInstance(\TYPO3\CMS\Fluid\View\StandaloneView::class); - $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/ModuleMenu/Main.html')); + $view = $this->getFluidTemplateObject('EXT:backend/Resources/Private/Templates/ModuleMenu/Main.html'); $view->assign('modules', $moduleStorage); return $view->render(); } @@ -777,4 +755,18 @@ class BackendController { $ajaxRequestHandler->addContent('menu', $content); $ajaxRequestHandler->setContentFormat('json'); } + + /** + * returns a new standalone view, shorthand function + * + * @param string $templatePathAndFileName optional the path to set the template path and filename + * @return \TYPO3\CMS\Fluid\View\StandaloneView + */ + protected function getFluidTemplateObject($templatePathAndFileName = NULL) { + $view = GeneralUtility::makeInstance(\TYPO3\CMS\Fluid\View\StandaloneView::class); + if ($templatePathAndFileName) { + $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templatePathAndFileName)); + } + return $view; + } } diff --git a/typo3/sysext/backend/Resources/Private/Templates/Backend/Main.html b/typo3/sysext/backend/Resources/Private/Templates/Backend/Main.html new file mode 100644 index 000000000000..b4680ec2be43 --- /dev/null +++ b/typo3/sysext/backend/Resources/Private/Templates/Backend/Main.html @@ -0,0 +1,11 @@ +<div class="navbar navbar-inverse x-hide-display" role="navigation" id="typo3-top-container"> + <div class="container-fluid"> + <div class="navbar-header" id="typo3-logo"><f:format.raw>{logo}</f:format.raw></div> + <div id="typo3-top"> + <ul class="nav navbar-nav navbar-right typo3-top-toolbar" id="typo3-toolbar"> + <f:format.raw>{toolbar}</f:format.raw> + </ul> + </div> + </div> +</div> +<f:format.raw>{moduleMenu}</f:format.raw> \ No newline at end of file diff --git a/typo3/sysext/backend/Resources/Public/JavaScript/Toolbar/UserMenu.js b/typo3/sysext/backend/Resources/Public/JavaScript/Toolbar/UserMenu.js deleted file mode 100644 index 4146287b1ed9..000000000000 --- a/typo3/sysext/backend/Resources/Public/JavaScript/Toolbar/UserMenu.js +++ /dev/null @@ -1,57 +0,0 @@ -/** - * 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! - */ - -/** - * module to handle the User menu on the top - */ -define('TYPO3/CMS/Backend/Toolbar/UserMenu', ['jquery'], function($) { - - var UserMenu = { - options: { - containerSelector: '#topbar-user-menu' - , toolbarItemSelector: '.toolbar-item' - , menuSelector: '.toolbar-item-menu' - , menuItemSelector: '.toolbar-item-menu li' - } - }; - - /** - * initialize the events for opening and closing the menu on clicking the - * toolbarItem and on one of the menuItems - */ - UserMenu.initializeEvents = function() { - $(UserMenu.options.toolbarItemSelector + ', ' + UserMenu.options.menuItemSelector, UserMenu.options.containerSelector).on('click', function() { - UserMenu.toggleMenu(); - }); - }; - - /** - * shows/hides the menu depending on the current state - */ - UserMenu.toggleMenu = function() { - $(UserMenu.options.menuSelector, UserMenu.options.containerSelector).toggle(); - }; - - /** - * initialize and return the Menu object - */ - return function() { - $(document).ready(function() { - UserMenu.initializeEvents(); - }); - - TYPO3.Toolbar = TYPO3.Toolbar || {}; - TYPO3.Toolbar.UserMenu = UserMenu; - return UserMenu; - }(); -}); \ No newline at end of file -- GitLab