[FEATURE] Page title providers visible in admin panel 16/61116/9
authorRiny van Tiggelen <info@online-gamer.nl>
Fri, 21 Jun 2019 15:23:39 +0000 (17:23 +0200)
committerDaniel Goerz <daniel.goerz@posteo.de>
Sat, 9 Nov 2019 16:22:58 +0000 (17:22 +0100)
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>
typo3/sysext/adminpanel/Classes/Modules/Debug/PageTitle.php [new file with mode: 0644]
typo3/sysext/adminpanel/Resources/Private/Language/locallang_debug.xlf
typo3/sysext/adminpanel/Resources/Private/Templates/Modules/Debug/PageTitle.html [new file with mode: 0644]
typo3/sysext/adminpanel/ext_localconf.php
typo3/sysext/core/Classes/PageTitle/PageTitleProviderManager.php

diff --git a/typo3/sysext/adminpanel/Classes/Modules/Debug/PageTitle.php b/typo3/sysext/adminpanel/Classes/Modules/Debug/PageTitle.php
new file mode 100644 (file)
index 0000000..8e9dd6d
--- /dev/null
@@ -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'];
+    }
+}
index d9b3e4e..a6ec7e5 100644 (file)
                        <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>
diff --git a/typo3/sysext/adminpanel/Resources/Private/Templates/Modules/Debug/PageTitle.html b/typo3/sysext/adminpanel/Resources/Private/Templates/Modules/Debug/PageTitle.html
new file mode 100644 (file)
index 0000000..d609cc0
--- /dev/null
@@ -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>
index 9b0ed48..67be9a4 100644 (file)
@@ -48,6 +48,9 @@ $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules'] = [
             'queryInformation' => [
                 'module' => \TYPO3\CMS\Adminpanel\Modules\Debug\QueryInformation::class,
             ],
+            'pageTitle' => [
+                'module' => \TYPO3\CMS\Adminpanel\Modules\Debug\PageTitle::class,
+            ]
         ],
     ],
 ];
index e20a587..46de0b4 100644 (file)
@@ -16,6 +16,8 @@ namespace TYPO3\CMS\Core\PageTitle;
  * 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;
@@ -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
  */
-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
     {
@@ -41,13 +43,26 @@ class PageTitleProviderManager implements SingletonInterface
         $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']]
+                );
             }
         }