From f37c70c5a150643927ba67afd36edb4980eeaf8a Mon Sep 17 00:00:00 2001 From: Riny van Tiggelen Date: Mon, 6 Jan 2025 20:30:32 +0100 Subject: [PATCH] [BUGFIX] Fixed the get_cache_timeout within StructuredDataProviderManager, introduced constant for the OverviewController request argument --- Classes/Controller/AjaxController.php | 2 +- Classes/Controller/OverviewController.php | 2 ++ .../LanguageMenu/LanguageMenuFactory.php | 5 +-- Classes/Service/Overview/OverviewService.php | 3 +- .../StructuredDataProviderManager.php | 31 +++++++++++++++++-- Configuration/Backend/AjaxRoutes.php | 2 +- 6 files changed, 38 insertions(+), 7 deletions(-) diff --git a/Classes/Controller/AjaxController.php b/Classes/Controller/AjaxController.php index 9cbd3c0f..a977dba9 100644 --- a/Classes/Controller/AjaxController.php +++ b/Classes/Controller/AjaxController.php @@ -34,7 +34,7 @@ public function saveScoresAction( return $this->saveScoresHandler->handle($request); } - public function promimentWordsAction( + public function prominentWordsAction( ServerRequestInterface $request ): ResponseInterface { return $this->prominentWordsHandler->handle($request); diff --git a/Classes/Controller/OverviewController.php b/Classes/Controller/OverviewController.php index 03a66946..739862b0 100644 --- a/Classes/Controller/OverviewController.php +++ b/Classes/Controller/OverviewController.php @@ -11,6 +11,8 @@ class OverviewController extends AbstractBackendController { + public const REQUEST_ARGUMENT = 'tx_yoastseo_yoast_yoastseooverview'; + public function __construct( protected ModuleTemplateFactory $moduleTemplateFactory, protected LanguageMenuFactory $languageMenuFactory, diff --git a/Classes/Service/Overview/LanguageMenu/LanguageMenuFactory.php b/Classes/Service/Overview/LanguageMenu/LanguageMenuFactory.php index 77e34c03..76d995da 100644 --- a/Classes/Service/Overview/LanguageMenu/LanguageMenuFactory.php +++ b/Classes/Service/Overview/LanguageMenu/LanguageMenuFactory.php @@ -11,6 +11,7 @@ use TYPO3\CMS\Core\Site\SiteFinder; use TYPO3\CMS\Extbase\Mvc\RequestInterface; use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder; +use YoastSeoForTypo3\YoastSeo\Controller\OverviewController; use YoastSeoForTypo3\YoastSeo\Service\Overview\Dto\LanguageMenuItem; use YoastSeoForTypo3\YoastSeo\Traits\BackendUserTrait; use YoastSeoForTypo3\YoastSeo\Traits\LanguageServiceTrait; @@ -94,7 +95,7 @@ protected function getLanguageMenuItems( ->setRequest($this->request) ->setTargetPageUid($this->pageUid) ->setArguments([ - 'tx_yoastseo_yoast_yoastseooverview' => [ + OverviewController::REQUEST_ARGUMENT => [ 'filter' => $filter, 'language' => $language->getLanguageId(), 'returnUrl' => $returnUrl, @@ -116,6 +117,6 @@ protected function getLanguageMenuItems( */ protected function getArguments(): array { - return $this->request->getArguments()['tx_yoastseo_yoast_yoastseooverview'] ?? $this->request->getArguments(); + return $this->request->getArguments()[OverviewController::REQUEST_ARGUMENT] ?? $this->request->getArguments(); } } diff --git a/Classes/Service/Overview/OverviewService.php b/Classes/Service/Overview/OverviewService.php index 40500d6a..d72d6410 100644 --- a/Classes/Service/Overview/OverviewService.php +++ b/Classes/Service/Overview/OverviewService.php @@ -7,6 +7,7 @@ use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Core\Type\Bitmask\Permission; use TYPO3\CMS\Extbase\Mvc\RequestInterface; +use YoastSeoForTypo3\YoastSeo\Controller\OverviewController; use YoastSeoForTypo3\YoastSeo\DataProviders\OverviewDataProviderInterface; use YoastSeoForTypo3\YoastSeo\Service\Overview\Dto\DataProviderRequest; use YoastSeoForTypo3\YoastSeo\Service\Overview\Dto\OverviewData; @@ -93,7 +94,7 @@ protected function getDataProviderRequest(RequestInterface $request): DataProvid { return new DataProviderRequest( (int)($request->getQueryParams()['id'] ?? 0), - (int)($request->getQueryParams()['tx_yoastseo_yoast_yoastseooverview']['language'] ?? $request->getQueryParams()['language'] ?? 0), + (int)($request->getQueryParams()[OverviewController::REQUEST_ARGUMENT]['language'] ?? $request->getQueryParams()['language'] ?? 0), 'pages' ); } diff --git a/Classes/StructuredData/StructuredDataProviderManager.php b/Classes/StructuredData/StructuredDataProviderManager.php index 0ac85716..dc866b52 100644 --- a/Classes/StructuredData/StructuredDataProviderManager.php +++ b/Classes/StructuredData/StructuredDataProviderManager.php @@ -6,11 +6,14 @@ use Psr\Http\Message\ServerRequestInterface; use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface; +use TYPO3\CMS\Core\Context\Context; use TYPO3\CMS\Core\Http\ApplicationType; +use TYPO3\CMS\Core\Information\Typo3Version; use TYPO3\CMS\Core\Service\DependencyOrderingService; use TYPO3\CMS\Core\SingletonInterface; use TYPO3\CMS\Core\TypoScript\TypoScriptService; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Frontend\Cache\CacheLifetimeCalculator; use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; /** @@ -82,8 +85,7 @@ public function getStructuredData(): array $cacheIdentifier, $data, ['pageId_' . ($this->getTypoScriptFrontendController()->page['uid'] ?? $this->getTypoScriptFrontendController()->id)], - // TODO: Fix this call, protected method since v13 - //$this->getTypoScriptFrontendController()->get_cache_timeout() + $this->getCacheTimeout(), ); } @@ -186,4 +188,29 @@ protected function getSourceComment(): string { return ''; } + + protected function getCacheTimeout(): int + { + if (GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() < 13) { + return $this->getTypoScriptFrontendController()->get_cache_timeout(); + } + + $request = $GLOBALS['TYPO3_REQUEST'] ?? null; + if ($request === null) { + return 0; + } + + $pageInformation = $request->getAttribute('frontend.page.information'); + $typoScriptConfigArray = $request->getAttribute('frontend.typoscript')->getConfigArray(); + $context = GeneralUtility::makeInstance(Context::class); + + return GeneralUtility::makeInstance(CacheLifetimeCalculator::class) + ->calculateLifetimeForPage( + $pageInformation->getId(), + $pageInformation->getPageRecord(), + $typoScriptConfigArray, + 0, + $context + ); + } } diff --git a/Configuration/Backend/AjaxRoutes.php b/Configuration/Backend/AjaxRoutes.php index 75c0d54c..e4a0fcaf 100644 --- a/Configuration/Backend/AjaxRoutes.php +++ b/Configuration/Backend/AjaxRoutes.php @@ -13,7 +13,7 @@ ], 'yoast_prominent_words' => [ 'path' => 'yoast/prominentwords', - 'target' => AjaxController::class . '::promimentWordsAction', + 'target' => AjaxController::class . '::prominentWordsAction', ], 'yoast_internal_linking_suggestions' => [ 'path' => 'yoast/internallinkingsuggestions',