Skip to content
Snippets Groups Projects
Commit 0a6320c1 authored by Benjamin Mack's avatar Benjamin Mack Committed by Wouter Wolters
Browse files

[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: default avatarAndreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: default avatarAndreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: default avatarWouter Wolters <typo3@wouterwolters.nl>
Tested-by: default avatarWouter Wolters <typo3@wouterwolters.nl>
parent fcfa8af9
Branches
Tags
No related merge requests found
......@@ -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;
}
}
<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
/**
* 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
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment