From 3a1a87bc05ee70c97ed1e1cf3c9db0e66d02d1fc Mon Sep 17 00:00:00 2001 From: Mathias Brodala Date: Sat, 17 Mar 2018 17:14:55 +0100 Subject: [PATCH] [TASK] Extract request processing from SystemInformationToolbarItem Change-Id: I32de5fa065db9184d1611b4b0025295705c3d01c Resolves: #84416 Releases: master Reviewed-on: https://review.typo3.org/56324 Tested-by: TYPO3com Reviewed-by: Anja Leichsenring Tested-by: Anja Leichsenring Reviewed-by: Christian Kuhn Tested-by: Christian Kuhn --- .../SystemInformationToolbarItem.php | 319 +++++++++--------- .../SystemInformationController.php | 50 +++ .../Configuration/Backend/AjaxRoutes.php | 2 +- 3 files changed, 205 insertions(+), 166 deletions(-) create mode 100644 typo3/sysext/backend/Classes/Controller/SystemInformationController.php diff --git a/typo3/sysext/backend/Classes/Backend/ToolbarItems/SystemInformationToolbarItem.php b/typo3/sysext/backend/Classes/Backend/ToolbarItems/SystemInformationToolbarItem.php index 197b8404bafd..d6b7ec6227ef 100644 --- a/typo3/sysext/backend/Classes/Backend/ToolbarItems/SystemInformationToolbarItem.php +++ b/typo3/sysext/backend/Classes/Backend/ToolbarItems/SystemInformationToolbarItem.php @@ -14,14 +14,12 @@ * The TYPO3 project - inspiring people to share! */ -use Psr\Http\Message\ResponseInterface; use TYPO3\CMS\Backend\Routing\UriBuilder; use TYPO3\CMS\Backend\Toolbar\Enumeration\InformationStatus; use TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface; use TYPO3\CMS\Core\Core\Environment; use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder; use TYPO3\CMS\Core\Database\ConnectionPool; -use TYPO3\CMS\Core\Http\HtmlResponse; use TYPO3\CMS\Core\Page\PageRenderer; use TYPO3\CMS\Core\Utility\CommandUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -86,6 +84,130 @@ public function __construct() $this->highestSeverity = InformationStatus::cast(InformationStatus::STATUS_INFO); } + /** + * Add a system message. + * This is a callback method for signal receivers. + * + * @param string $text The text to be displayed + * @param string $status The status of this system message + * @param int $count Will be added to the total count + * @param string $module The associated module + * @param string $params Query string with additional parameters + */ + public function addSystemMessage($text, $status = InformationStatus::STATUS_OK, $count = 0, $module = '', $params = '') + { + $this->totalCount += (int)$count; + + /** @var InformationStatus $messageSeverity */ + $messageSeverity = InformationStatus::cast($status); + // define the severity for the badge + if ($messageSeverity->isGreaterThan($this->highestSeverity)) { + $this->highestSeverity = $messageSeverity; + } + + $this->systemMessages[] = [ + 'module' => $module, + 'params' => $params, + 'count' => (int)$count, + 'status' => $messageSeverity, + 'text' => $text + ]; + } + + /** + * Add a system information. + * This is a callback method for signal receivers. + * + * @param string $title The title of this system information + * @param string $value The associated value + * @param string $iconIdentifier The icon identifier + * @param string $status The status of this system information + */ + public function addSystemInformation($title, $value, $iconIdentifier, $status = InformationStatus::STATUS_NOTICE) + { + $this->systemInformation[] = [ + 'title' => $title, + 'value' => $value, + 'iconIdentifier' => $iconIdentifier, + 'status' => $status + ]; + } + + /** + * Checks whether the user has access to this toolbar item + * + * @return bool TRUE if user has access, FALSE if not + */ + public function checkAccess() + { + return $this->getBackendUserAuthentication()->isAdmin(); + } + + /** + * Render system information dropdown + * + * @return string Icon HTML + */ + public function getItem() + { + return $this->getFluidTemplateObject('SystemInformationToolbarItem.html')->render(); + } + + /** + * Render drop down + * + * @return string Drop down HTML + */ + public function getDropDown() + { + if (!$this->checkAccess()) { + return ''; + } + + $this->collectInformation(); + + $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); + $view = $this->getFluidTemplateObject('SystemInformationDropDown.html'); + $view->assignMultiple([ + 'environmentToolUrl' => (string)$uriBuilder->buildUriFromRoute('tools_toolsenvironment'), + 'messages' => $this->systemMessages, + 'count' => $this->totalCount > $this->maximumCountInBadge ? $this->maximumCountInBadge . '+' : $this->totalCount, + 'severityBadgeClass' => $this->severityBadgeClass, + 'systemInformation' => $this->systemInformation + ]); + return $view->render(); + } + + /** + * No additional attributes needed. + * + * @return array + */ + public function getAdditionalAttributes() + { + return []; + } + + /** + * This item has a drop down + * + * @return bool + */ + public function hasDropDown() + { + return true; + } + + /** + * Position relative to others + * + * @return int + */ + public function getIndex() + { + return 75; + } + /** * Collect the information for the menu */ @@ -107,14 +229,27 @@ protected function collectInformation() } /** - * Renders the menu for AJAX calls - * - * @return ResponseInterface + * Gets the TYPO3 version */ - public function renderMenuAction(): ResponseInterface + protected function getTypo3Version() { - $this->collectInformation(); - return new HtmlResponse($this->getDropDown()); + $this->systemInformation[] = [ + 'title' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:toolbarItems.sysinfo.typo3-version', + 'value' => VersionNumberUtility::getCurrentTypo3Version(), + 'iconIdentifier' => 'sysinfo-typo3-version' + ]; + } + + /** + * Gets the webserver software + */ + protected function getWebServer() + { + $this->systemInformation[] = [ + 'title' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:toolbarItems.sysinfo.webserver', + 'value' => $_SERVER['SERVER_SOFTWARE'], + 'iconIdentifier' => 'sysinfo-webserver' + ]; } /** @@ -225,30 +360,6 @@ protected function getOperatingSystem() ]; } - /** - * Gets the webserver software - */ - protected function getWebServer() - { - $this->systemInformation[] = [ - 'title' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:toolbarItems.sysinfo.webserver', - 'value' => $_SERVER['SERVER_SOFTWARE'], - 'iconIdentifier' => 'sysinfo-webserver' - ]; - } - - /** - * Gets the TYPO3 version - */ - protected function getTypo3Version() - { - $this->systemInformation[] = [ - 'title' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:toolbarItems.sysinfo.typo3-version', - 'value' => VersionNumberUtility::getCurrentTypo3Version(), - 'iconIdentifier' => 'sysinfo-typo3-version' - ]; - } - /** * Emits the "getSystemInformation" signal */ @@ -266,125 +377,22 @@ protected function emitLoadMessages() } /** - * Add a system message. - * This is a callback method for signal receivers. - * - * @param string $text The text to be displayed - * @param string $status The status of this system message - * @param int $count Will be added to the total count - * @param string $module The associated module - * @param string $params Query string with additional parameters - */ - public function addSystemMessage($text, $status = InformationStatus::STATUS_OK, $count = 0, $module = '', $params = '') - { - $this->totalCount += (int)$count; - - /** @var InformationStatus $messageSeverity */ - $messageSeverity = InformationStatus::cast($status); - // define the severity for the badge - if ($messageSeverity->isGreaterThan($this->highestSeverity)) { - $this->highestSeverity = $messageSeverity; - } - - $this->systemMessages[] = [ - 'module' => $module, - 'params' => $params, - 'count' => (int)$count, - 'status' => $messageSeverity, - 'text' => $text - ]; - } - - /** - * Add a system information. - * This is a callback method for signal receivers. - * - * @param string $title The title of this system information - * @param string $value The associated value - * @param string $iconIdentifier The icon identifier - * @param string $status The status of this system information - */ - public function addSystemInformation($title, $value, $iconIdentifier, $status = InformationStatus::STATUS_NOTICE) - { - $this->systemInformation[] = [ - 'title' => $title, - 'value' => $value, - 'iconIdentifier' => $iconIdentifier, - 'status' => $status - ]; - } - - /** - * Checks whether the user has access to this toolbar item - * - * @return bool TRUE if user has access, FALSE if not - */ - public function checkAccess() - { - return $this->getBackendUserAuthentication()->isAdmin(); - } - - /** - * Render system information dropdown - * - * @return string Icon HTML - */ - public function getItem() - { - return $this->getFluidTemplateObject('SystemInformationToolbarItem.html')->render(); - } - - /** - * Render drop down - * - * @return string Drop down HTML - */ - public function getDropDown() - { - if (!$this->checkAccess()) { - return ''; - } - - $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); - $view = $this->getFluidTemplateObject('SystemInformationDropDown.html'); - $view->assignMultiple([ - 'environmentToolUrl' => (string)$uriBuilder->buildUriFromRoute('tools_toolsenvironment'), - 'messages' => $this->systemMessages, - 'count' => $this->totalCount > $this->maximumCountInBadge ? $this->maximumCountInBadge . '+' : $this->totalCount, - 'severityBadgeClass' => $this->severityBadgeClass, - 'systemInformation' => $this->systemInformation - ]); - return $view->render(); - } - - /** - * No additional attributes needed. + * Returns a new standalone view, shorthand function * - * @return array + * @param string $filename Which templateFile should be used. + * @return StandaloneView */ - public function getAdditionalAttributes() + protected function getFluidTemplateObject(string $filename): StandaloneView { - return []; - } + $view = GeneralUtility::makeInstance(StandaloneView::class); + $view->setLayoutRootPaths(['EXT:backend/Resources/Private/Layouts']); + $view->setPartialRootPaths(['EXT:backend/Resources/Private/Partials/ToolbarItems']); + $view->setTemplateRootPaths(['EXT:backend/Resources/Private/Templates/ToolbarItems']); - /** - * This item has a drop down - * - * @return bool - */ - public function hasDropDown() - { - return true; - } + $view->setTemplate($filename); - /** - * Position relative to others - * - * @return int - */ - public function getIndex() - { - return 75; + $view->getRequest()->setControllerExtensionName('Backend'); + return $view; } /** @@ -419,23 +427,4 @@ protected function getSignalSlotDispatcher() } return $this->signalSlotDispatcher; } - - /** - * Returns a new standalone view, shorthand function - * - * @param string $filename Which templateFile should be used. - * @return StandaloneView - */ - protected function getFluidTemplateObject(string $filename): StandaloneView - { - $view = GeneralUtility::makeInstance(StandaloneView::class); - $view->setLayoutRootPaths(['EXT:backend/Resources/Private/Layouts']); - $view->setPartialRootPaths(['EXT:backend/Resources/Private/Partials/ToolbarItems']); - $view->setTemplateRootPaths(['EXT:backend/Resources/Private/Templates/ToolbarItems']); - - $view->setTemplate($filename); - - $view->getRequest()->setControllerExtensionName('Backend'); - return $view; - } } diff --git a/typo3/sysext/backend/Classes/Controller/SystemInformationController.php b/typo3/sysext/backend/Classes/Controller/SystemInformationController.php new file mode 100644 index 000000000000..8efbd8fdcb28 --- /dev/null +++ b/typo3/sysext/backend/Classes/Controller/SystemInformationController.php @@ -0,0 +1,50 @@ +toolbarItem = GeneralUtility::makeInstance(SystemInformationToolbarItem::class); + } + + /** + * Renders the menu for AJAX calls + * + * @return ResponseInterface + */ + public function renderMenuAction(): ResponseInterface + { + return new HtmlResponse($this->toolbarItem->getDropDown()); + } +} diff --git a/typo3/sysext/backend/Configuration/Backend/AjaxRoutes.php b/typo3/sysext/backend/Configuration/Backend/AjaxRoutes.php index 7cc756d389cf..5f1383e6dfdc 100644 --- a/typo3/sysext/backend/Configuration/Backend/AjaxRoutes.php +++ b/typo3/sysext/backend/Configuration/Backend/AjaxRoutes.php @@ -122,7 +122,7 @@ // Render systeminformtion toolbar item 'systeminformation_render' => [ 'path' => '/system-information/render', - 'target' => \TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem::class . '::renderMenuAction', + 'target' => \TYPO3\CMS\Backend\Controller\SystemInformationController::class . '::renderMenuAction', 'parameters' => [ 'skipSessionUpdate' => 1 ]