Skip to content

Commit

Permalink
[FEATURE] Page title providers visible in admin panel
Browse files Browse the repository at this point in the history
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: TYPO3com <noreply@typo3.com>
Tested-by: Susanne Moog <look@susi.dev>
Tested-by: Daniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Susanne Moog <look@susi.dev>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
  • Loading branch information
RinyVT authored and ervaude committed Nov 9, 2019
1 parent 4f12e25 commit a017b4b
Show file tree
Hide file tree
Showing 5 changed files with 237 additions and 3 deletions.
124 changes: 124 additions & 0 deletions typo3/sysext/adminpanel/Classes/Modules/Debug/PageTitle.php
@@ -0,0 +1,124 @@
<?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'];
}
}
Expand Up @@ -58,6 +58,33 @@
<trans-unit id="submodule.queryInformation.queryTime" resname="submodule.queryInformation.queryTime">
<source>Total Time [ms]</source>
</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>
</file>
</xliff>
@@ -0,0 +1,65 @@
<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>
3 changes: 3 additions & 0 deletions typo3/sysext/adminpanel/ext_localconf.php
Expand Up @@ -48,6 +48,9 @@
'queryInformation' => [
'module' => \TYPO3\CMS\Adminpanel\Modules\Debug\QueryInformation::class,
],
'pageTitle' => [
'module' => \TYPO3\CMS\Adminpanel\Modules\Debug\PageTitle::class,
]
],
],
];
Expand Down
21 changes: 18 additions & 3 deletions typo3/sysext/core/Classes/PageTitle/PageTitleProviderManager.php
Expand Up @@ -16,6 +16,8 @@
* 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\SingletonInterface;
use TYPO3\CMS\Core\TypoScript\TypoScriptService;
Expand All @@ -24,12 +26,12 @@
/**
* 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
* @throws \TYPO3\CMS\Core\Cache\Exception
* @throws \TYPO3\CMS\Core\Cache\Exception\InvalidDataException
*/
public function getTitle(): string
{
Expand All @@ -41,13 +43,26 @@ public function getTitle(): string
$orderedTitleProviders = GeneralUtility::makeInstance(DependencyOrderingService::class)
->orderByDependencies($titleProviders);

$this->logger->debug(
'Page title providers ordered',
['orderedTitleProviders' => $orderedTitleProviders]
);

foreach ($orderedTitleProviders as $provider => $configuration) {
if (class_exists($configuration['provider']) && is_subclass_of($configuration['provider'], PageTitleProviderInterface::class)) {
/** @var PageTitleProviderInterface $titleProviderObject */
$titleProviderObject = GeneralUtility::makeInstance($configuration['provider']);
if ($pageTitle = $titleProviderObject->getTitle()) {
$this->logger->debug(
'Page title provider ' . $configuration['provider'] . ' used',
['title' => $pageTitle, 'providerUsed' => $configuration['provider']]
);
break;
}
$this->logger->debug(
'Page title provider ' . $configuration['provider'] . ' skipped',
['name' => $provider, 'skippedProvider' => $configuration['provider']]
);
}
}

Expand Down

0 comments on commit a017b4b

Please sign in to comment.