Skip to content

Commit

Permalink
[TASK] Extract request processing from SystemInformationToolbarItem
Browse files Browse the repository at this point in the history
Change-Id: I32de5fa065db9184d1611b4b0025295705c3d01c
Resolves: #84416
Releases: master
Reviewed-on: https://review.typo3.org/56324
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: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
  • Loading branch information
mbrodala authored and lolli42 committed Mar 18, 2018
1 parent ff0ee37 commit 3a1a87b
Show file tree
Hide file tree
Showing 3 changed files with 205 additions and 166 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*/
Expand All @@ -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'
];
}

/**
Expand Down Expand Up @@ -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
*/
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 3a1a87b

Please sign in to comment.