Commit a017b4b9 authored by Riny van Tiggelen's avatar Riny van Tiggelen Committed by Daniel Goerz
Browse files

[FEATURE] Page title providers visible in admin panel

The PageTitleProviders are now visible within the adminpanel debug panel.
Since this information is in no way available when the page is cached,
there's a message to view the page in uncached mode.

Resolves: #88609
Releases: master
Change-Id: I15b3187fb219ea488ea88950906545391994bc24
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/61116


Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: Susanne Moog's avatarSusanne Moog <look@susi.dev>
Tested-by: Daniel Goerz's avatarDaniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Susanne Moog's avatarSusanne Moog <look@susi.dev>
Reviewed-by: Daniel Goerz's avatarDaniel Goerz <daniel.goerz@posteo.de>
parent 4f12e25e
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Adminpanel\Modules\Debug;
/*
* 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!
*/
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Adminpanel\Log\InMemoryLogWriter;
use TYPO3\CMS\Adminpanel\ModuleApi\AbstractSubModule;
use TYPO3\CMS\Adminpanel\ModuleApi\DataProviderInterface;
use TYPO3\CMS\Adminpanel\ModuleApi\ModuleData;
use TYPO3\CMS\Fluid\View\StandaloneView;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
/**
* Admin Panel Page Title module for showing the Page title providers
*
* @internal
*/
class PageTitle extends AbstractSubModule implements DataProviderInterface
{
/**
* Log component
*/
protected const LOG_COMPONENT = 'TYPO3.CMS.Core.PageTitle.PageTitleProviderManager';
/**
* Identifier for this Sub-module,
* for example "preview" or "cache"
*
* @return string
*/
public function getIdentifier(): string
{
return 'debug_pagetitle';
}
/**
* Sub-Module label
*
* @return string
*/
public function getLabel(): string
{
return $this->getLanguageService()->sL(
'LLL:EXT:adminpanel/Resources/Private/Language/locallang_debug.xlf:submodule.pageTitle.label'
);
}
/**
* @param ServerRequestInterface $request
* @return \TYPO3\CMS\Adminpanel\ModuleApi\ModuleData
*/
public function getDataToStore(ServerRequestInterface $request): ModuleData
{
if ($this->isNoCacheEnabled()) {
$data = [
'orderedProviders' => [],
'usedProvider' => null,
'skippedProviders' => []
];
$log = InMemoryLogWriter::$log;
/** @var \TYPO3\CMS\Core\Log\LogRecord $logEntry */
foreach ($log as $logEntry) {
if ($logEntry->getComponent() === self::LOG_COMPONENT) {
if (isset($logEntry->getData()['orderedTitleProviders'])) {
$data['orderedProviders'] = $logEntry->getData()['orderedTitleProviders'];
} elseif (isset($logEntry->getData()['providerUsed'])) {
$data['usedProvider'] = $logEntry->getData();
} elseif (isset($logEntry->getData()['skippedProvider'])) {
$data['skippedProviders'][] = $logEntry->getData();
}
}
}
} else {
$data['cacheEnabled'] = true;
}
return new ModuleData($data);
}
/**
* @param \TYPO3\CMS\Adminpanel\ModuleApi\ModuleData $data
* @return string Returns content of admin panel
*/
public function getContent(ModuleData $data): string
{
$view = new StandaloneView();
$view->setTemplatePathAndFilename(
'EXT:adminpanel/Resources/Private/Templates/Modules/Debug/PageTitle.html'
);
$this->getLanguageService()->includeLLFile('EXT:adminpanel/Resources/Private/Language/locallang_debug.xlf');
$view->assignMultiple($data->getArrayCopy());
return $view->render();
}
/**
* @return bool
*/
protected function isNoCacheEnabled(): bool
{
return (bool)$this->getTypoScriptFrontendController()->no_cache;
}
/**
* @return TypoScriptFrontendController
*/
protected function getTypoScriptFrontendController(): TypoScriptFrontendController
{
return $GLOBALS['TSFE'];
}
}
...@@ -58,6 +58,33 @@ ...@@ -58,6 +58,33 @@
<trans-unit id="submodule.queryInformation.queryTime" resname="submodule.queryInformation.queryTime"> <trans-unit id="submodule.queryInformation.queryTime" resname="submodule.queryInformation.queryTime">
<source>Total Time [ms]</source> <source>Total Time [ms]</source>
</trans-unit> </trans-unit>
<trans-unit id="submodule.pageTitle.label">
<source>Page title</source>
</trans-unit>
<trans-unit id="submodule.pageTitle.usedProvider">
<source>Used provider</source>
</trans-unit>
<trans-unit id="submodule.pageTitle.title">
<source>Title</source>
</trans-unit>
<trans-unit id="submodule.pageTitle.provider">
<source>Provider</source>
</trans-unit>
<trans-unit id="submodule.pageTitle.skippedProviders">
<source>Skipped providers (provided no title)</source>
</trans-unit>
<trans-unit id="submodule.pageTitle.name">
<source>Name</source>
</trans-unit>
<trans-unit id="submodule.pageTitle.allProviders">
<source>All providers checked in order</source>
</trans-unit>
<trans-unit id="submodule.pageTitle.cacheEnabled">
<source>It's not possible to retrieve the page title (providers) information when the page is cached.</source>
</trans-unit>
<trans-unit id="submodule.pageTitle.cacheEnabled.extraInfo">
<source>Visit this page uncached, or disable the cache through this admin panel.</source>
</trans-unit>
</body> </body>
</file> </file>
</xliff> </xliff>
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<f:if condition="{cacheEnabled}">
<f:then>
<p><f:translate key="LLL:EXT:adminpanel/Resources/Private/Language/locallang_debug.xlf:submodule.pageTitle.cacheEnabled" /></p>
<p><f:translate key="LLL:EXT:adminpanel/Resources/Private/Language/locallang_debug.xlf:submodule.pageTitle.cacheEnabled.extraInfo" /></p>
</f:then>
<f:else>
<h2 class="typo3-adminPanel-headline"><f:translate key="LLL:EXT:adminpanel/Resources/Private/Language/locallang_debug.xlf:submodule.pageTitle.usedProvider" /></h2>
<div class="typo3-adminPanel-table-overflow">
<table class="typo3-adminPanel-table typo3-adminPanel-table-debug">
<thead>
<tr>
<th scope="col" class="typo3-adminPanel-table-cell-key"><f:translate key="LLL:EXT:adminpanel/Resources/Private/Language/locallang_debug.xlf:submodule.pageTitle.title" /></th>
<th scope="col" class="typo3-adminPanel-table-cell-key"><f:translate key="LLL:EXT:adminpanel/Resources/Private/Language/locallang_debug.xlf:submodule.pageTitle.provider" /></th>
</tr>
</thead>
<tbody>
<tr>
<td>{usedProvider.title}</td>
<td>{usedProvider.providerUsed}</td>
</tr>
</tbody>
</table>
</div>
<h2 class="typo3-adminPanel-headline"><f:translate key="LLL:EXT:adminpanel/Resources/Private/Language/locallang_debug.xlf:submodule.pageTitle.skippedProviders" /></h2>
<div class="typo3-adminPanel-table-overflow">
<table class="typo3-adminPanel-table typo3-adminPanel-table-debug">
<thead>
<tr>
<th scope="col" class="typo3-adminPanel-table-cell-key"><f:translate key="LLL:EXT:adminpanel/Resources/Private/Language/locallang_debug.xlf:submodule.pageTitle.name" /></th>
<th scope="col" class="typo3-adminPanel-table-cell-key"><f:translate key="LLL:EXT:adminpanel/Resources/Private/Language/locallang_debug.xlf:submodule.pageTitle.provider" /></th>
</tr>
</thead>
<tbody>
<f:for each="{skippedProviders}" as="providerInformation">
<tr>
<td>{providerInformation.name}</td>
<td>{providerInformation.skippedProvider}</td>
</tr>
</f:for>
</tbody>
</table>
</div>
<h2 class="typo3-adminPanel-headline"><f:translate key="LLL:EXT:adminpanel/Resources/Private/Language/locallang_debug.xlf:submodule.pageTitle.allProviders" /></h2>
<div class="typo3-adminPanel-table-overflow">
<table class="typo3-adminPanel-table typo3-adminPanel-table-debug">
<thead>
<tr>
<th scope="col" class="typo3-adminPanel-table-cell-key"><f:translate key="LLL:EXT:adminpanel/Resources/Private/Language/locallang_debug.xlf:submodule.pageTitle.name" /></th>
<th scope="col" class="typo3-adminPanel-table-cell-key"><f:translate key="LLL:EXT:adminpanel/Resources/Private/Language/locallang_debug.xlf:submodule.pageTitle.provider" /></th>
</tr>
</thead>
<tbody>
<f:for each="{orderedProviders}" as="providerInformation" key="name">
<tr>
<td>{name}</td>
<td>{providerInformation.provider}</td>
</tr>
</f:for>
</tbody>
</table>
</div>
</f:else>
</f:if>
</html>
...@@ -48,6 +48,9 @@ $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules'] = [ ...@@ -48,6 +48,9 @@ $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules'] = [
'queryInformation' => [ 'queryInformation' => [
'module' => \TYPO3\CMS\Adminpanel\Modules\Debug\QueryInformation::class, 'module' => \TYPO3\CMS\Adminpanel\Modules\Debug\QueryInformation::class,
], ],
'pageTitle' => [
'module' => \TYPO3\CMS\Adminpanel\Modules\Debug\PageTitle::class,
]
], ],
], ],
]; ];
......
...@@ -16,6 +16,8 @@ namespace TYPO3\CMS\Core\PageTitle; ...@@ -16,6 +16,8 @@ namespace TYPO3\CMS\Core\PageTitle;
* The TYPO3 project - inspiring people to share! * The TYPO3 project - inspiring people to share!
*/ */
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use TYPO3\CMS\Core\Service\DependencyOrderingService; use TYPO3\CMS\Core\Service\DependencyOrderingService;
use TYPO3\CMS\Core\SingletonInterface; use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\TypoScript\TypoScriptService; use TYPO3\CMS\Core\TypoScript\TypoScriptService;
...@@ -24,12 +26,12 @@ use TYPO3\CMS\Core\Utility\GeneralUtility; ...@@ -24,12 +26,12 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
/** /**
* This class will take care of the different providers and returns the title with the highest priority * This class will take care of the different providers and returns the title with the highest priority
*/ */
class PageTitleProviderManager implements SingletonInterface class PageTitleProviderManager implements SingletonInterface, LoggerAwareInterface
{ {
use LoggerAwareTrait;
/** /**
* @return string * @return string
* @throws \TYPO3\CMS\Core\Cache\Exception
* @throws \TYPO3\CMS\Core\Cache\Exception\InvalidDataException
*/ */
public function getTitle(): string public function getTitle(): string
{ {
...@@ -41,13 +43,26 @@ class PageTitleProviderManager implements SingletonInterface ...@@ -41,13 +43,26 @@ class PageTitleProviderManager implements SingletonInterface
$orderedTitleProviders = GeneralUtility::makeInstance(DependencyOrderingService::class) $orderedTitleProviders = GeneralUtility::makeInstance(DependencyOrderingService::class)
->orderByDependencies($titleProviders); ->orderByDependencies($titleProviders);
$this->logger->debug(
'Page title providers ordered',
['orderedTitleProviders' => $orderedTitleProviders]
);
foreach ($orderedTitleProviders as $provider => $configuration) { foreach ($orderedTitleProviders as $provider => $configuration) {
if (class_exists($configuration['provider']) && is_subclass_of($configuration['provider'], PageTitleProviderInterface::class)) { if (class_exists($configuration['provider']) && is_subclass_of($configuration['provider'], PageTitleProviderInterface::class)) {
/** @var PageTitleProviderInterface $titleProviderObject */ /** @var PageTitleProviderInterface $titleProviderObject */
$titleProviderObject = GeneralUtility::makeInstance($configuration['provider']); $titleProviderObject = GeneralUtility::makeInstance($configuration['provider']);
if ($pageTitle = $titleProviderObject->getTitle()) { if ($pageTitle = $titleProviderObject->getTitle()) {
$this->logger->debug(
'Page title provider ' . $configuration['provider'] . ' used',
['title' => $pageTitle, 'providerUsed' => $configuration['provider']]
);
break; break;
} }
$this->logger->debug(
'Page title provider ' . $configuration['provider'] . ' skipped',
['name' => $provider, 'skippedProvider' => $configuration['provider']]
);
} }
} }
......
Supports Markdown
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