Commit 2ea7f0c5 authored by Nikita Hovratov's avatar Nikita Hovratov Committed by Benni Mack
Browse files

[FEATURE] Allow icon identifiers in the report module registration

To further streamline the usage of the IconRegistry, the reports
registration array now allows to define an icon identifier. Absolute
paths and paths with "EXT:" prefix are still possible.

Further improvements:
The IconViewHelper of the reports extension has been dropped. It had
the same functionality as a normal ImageViewHelper with the addition of
a fallback icon. This logic has been moved to the controller action.

Some minor code refactoring and template cleanup while at it.

Resolves: #94588
Resolves: #94590
Releases: master
Change-Id: I901b8a0c56f26459c609a36a59c67b341c6b4168
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/69965

Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent 20e7e865
.. include:: ../../Includes.txt
======================================================================
Feature: #94590 - Allow icon identifiers in report module registration
======================================================================
See :issue:`94590`
Description
===========
To further streamline the usage of the IconRegistry, the reports registration
array now allows to define icon identifiers for the :php:`icon` key. Absolute
paths and paths with `EXT:` prefix are still possible.
Example:
::
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports']['tx_reports']['status'] = [
'title' => 'LLL:EXT:reports/Resources/Private/Language/locallang_reports.xlf:status_report_title',
'icon' => 'module-reports', // Icon identifiers are now possible here.
'description' => 'LLL:EXT:reports/Resources/Private/Language/locallang_reports.xlf:status_report_description',
'report' => \TYPO3\CMS\Reports\Report\Status\Status::class
];
Impact
======
Developers are now able to provide icon identifiers in the reports module
registration array.
.. index:: Backend, PHP-API, ext:reports
......@@ -25,7 +25,9 @@ use TYPO3\CMS\Backend\Template\ModuleTemplateFactory;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Http\HtmlResponse;
use TYPO3\CMS\Core\Http\RedirectResponse;
use TYPO3\CMS\Core\Imaging\IconRegistry;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
use TYPO3\CMS\Reports\ReportInterface;
......@@ -59,13 +61,16 @@ class ReportController
protected UriBuilder $uriBuilder;
protected ModuleTemplateFactory $moduleTemplateFactory;
protected IconRegistry $iconRegistry;
public function __construct(
UriBuilder $uriBuilder,
ModuleTemplateFactory $moduleTemplateFactory
ModuleTemplateFactory $moduleTemplateFactory,
IconRegistry $iconRegistry
) {
$this->uriBuilder = $uriBuilder;
$this->moduleTemplateFactory = $moduleTemplateFactory;
$this->iconRegistry = $iconRegistry;
}
/**
......@@ -152,7 +157,20 @@ class ReportController
$this->getLanguageService()->sL('LLL:EXT:reports/Resources/Private/Language/locallang.xlf:mlang_tabs_tab'),
$this->getLanguageService()->sL('LLL:EXT:reports/Resources/Private/Language/locallang.xlf:reports_overview')
);
$this->view->assign('reports', $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports']);
$reports = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'];
foreach ($reports as $extension => $reportModules) {
foreach ($reportModules as $module => $configuration) {
if (!isset($configuration['icon']) || !$configuration['icon']) {
$fallbackIconPath = ExtensionManagementUtility::extPath('reports');
$reports[$extension][$module]['icon'] = ExtensionManagementUtility::getExtensionIcon($fallbackIconPath, true);
}
$reports[$extension][$module]['isIconIdentifier'] = $this->iconRegistry->isRegistered($configuration['icon']);
}
}
$this->view->assign('reports', $reports);
$this->saveState();
}
......
<?php
/*
* 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!
*/
namespace TYPO3\CMS\Reports\ViewHelpers;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\PathUtility;
use TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
/**
* Render the icon of a report
*
* @internal
*/
class IconViewHelper extends AbstractBackendViewHelper
{
/**
* As this ViewHelper renders HTML, the output must not be escaped.
*
* @var bool
*/
protected $escapeOutput = false;
/**
* Initializes the arguments
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('icon', 'string', 'Icon to be used', true);
$this->registerArgument('title', 'string', 'Optional title', false, '');
}
/**
* Renders the icon
*
* @return string Content rendered image
*/
public function render()
{
return static::renderStatic(
$this->arguments,
$this->buildRenderChildrenClosure(),
$this->renderingContext
);
}
/**
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
*
* @return string
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
$icon = $arguments['icon'];
$title = $arguments['title'];
$icon = GeneralUtility::getFileAbsFileName($icon);
// use the extension icon from EXT:reports as fallback
if (!$icon) {
$fallbackIconPath = ExtensionManagementUtility::extPath('reports');
$icon = ExtensionManagementUtility::getExtensionIcon($fallbackIconPath, true);
}
return '<img src="' . htmlspecialchars(PathUtility::getAbsoluteWebPath($icon))
. '" width="16" height="16" title="' . htmlspecialchars($title)
. '" alt="' . htmlspecialchars($title) . '" />';
}
}
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
xmlns:r="http://typo3.org/ns/TYPO3/CMS/Reports/ViewHelpers"
xmlns:be="http://typo3.org/ns/TYPO3/CMS/Backend/ViewHelpers"
data-namespace-typo3-fluid="true">
<html xmlns:be="http://typo3.org/ns/TYPO3/CMS/Backend/ViewHelpers" data-namespace-typo3-fluid="true">
<f:layout name="Default" />
<f:layout name="Default"/>
<f:section name="content">
<h1><f:translate key="title" /></h1>
<h1><f:translate key="title"/></h1>
<h2 class="uppercase"><f:translate key="reports_overview" /></h2>
<h2><f:translate key="reports_overview"/></h2>
<dl class="t3-overview-list">
<f:for each="{reports}" as="reportOverview" key="extensionKey">
<f:for each="{reportOverview}" key="reportName" as="report">
<dt>
<a href="{be:moduleLink(route:'system_reports',arguments:'{action:\'detail\', extension:extensionKey, report:reportName}')}">
<r:icon icon="{report.icon}" title="{f:translate(key:report.title)}" />
<f:translate key="{report.title}" />
<a href="{be:moduleLink(route: 'system_reports', arguments: '{action: \'detail\', extension: extensionKey, report: reportName}')}">
<f:if condition="{report.isIconIdentifier}">
<f:then>
<core:icon identifier="{report.icon}"/>
</f:then>
<f:else>
<f:image src="{report.icon}" width="16" height="16"/>
</f:else>
</f:if>
<f:translate key="{report.title}"/>
</a>
</dt>
<dd><f:translate key="{report.description}" /></dd>
<dd><f:translate key="{report.description}"/></dd>
</f:for>
</f:for>
</dl>
......
......@@ -18,11 +18,12 @@ $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports']['tx_reports']['status'] = a
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports']['tx_reports']['status'],
[
'title' => 'LLL:EXT:reports/Resources/Private/Language/locallang_reports.xlf:status_report_title',
'icon' => 'EXT:reports/Resources/Public/Icons/module-reports.svg',
'icon' => 'module-reports',
'description' => 'LLL:EXT:reports/Resources/Private/Language/locallang_reports.xlf:status_report_description',
'report' => \TYPO3\CMS\Reports\Report\Status\Status::class
]
);
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports']['tx_reports']['status']['providers']['typo3'][] = \TYPO3\CMS\Reports\Report\Status\Typo3Status::class;
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports']['tx_reports']['status']['providers']['system'][] = \TYPO3\CMS\Reports\Report\Status\SystemStatus::class;
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports']['tx_reports']['status']['providers']['security'][] = \TYPO3\CMS\Reports\Report\Status\SecurityStatus::class;
......
Markdown is supported
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