diff --git a/Build/phpstan11.neon b/Build/phpstan11.neon index 8bf0294..61940a7 100644 --- a/Build/phpstan11.neon +++ b/Build/phpstan11.neon @@ -16,3 +16,5 @@ parameters: - message: '#.*unknown class TYPO3\\CMS\\Core\\TypoScript\\FrontendTypoScript.#' path: %currentWorkingDirectory%/Classes/CacheHelper.php + - + message: '#Instantiated class TYPO3\\CMS\\Core\\Cache\\CacheDataCollector not found.#' diff --git a/Build/phpstan12.neon b/Build/phpstan12.neon index e8f1027..bf27040 100644 --- a/Build/phpstan12.neon +++ b/Build/phpstan12.neon @@ -16,3 +16,5 @@ parameters: - message: '#Call to an undefined method TYPO3\\CMS\\Core\\TypoScript\\FrontendTypoScript::getConfigArray\(\).#' path: %currentWorkingDirectory%/Classes/CacheHelper.php + - + message: '#Instantiated class TYPO3\\CMS\\Core\\Cache\\CacheDataCollector not found.#' diff --git a/Classes/CacheHelper.php b/Classes/CacheHelper.php index 4fedd6e..4eca271 100644 --- a/Classes/CacheHelper.php +++ b/Classes/CacheHelper.php @@ -12,6 +12,7 @@ */ use Psr\Http\Message\ServerRequestInterface; +use TYPO3\CMS\Core\Cache\CacheTag; use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface; use TYPO3\CMS\Core\Context\Context; use TYPO3\CMS\Core\Context\Exception\AspectNotFoundException; @@ -86,7 +87,13 @@ protected function buildTagsAndAddThemToPageCache(array $pages): array $tags = array_map(function ($pageId) { return 'menuId_' . $pageId; }, $usedPageIds); - $this->getFrontendController()->addCacheTags($tags); + + if (GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() < 13) { + $this->getFrontendController()->addCacheTags($tags); + } else { + $cacheDataCollector = $this->getServerRequest()->getAttribute('frontend.cache.collector'); + $cacheDataCollector->addCacheTags(...array_map(fn (string $tag) => new CacheTag($tag), $tags)); + } return $tags; } diff --git a/Tests/Functional/DataProcessing/ListMenuProcessorTest.php b/Tests/Functional/DataProcessing/ListMenuProcessorTest.php index 5459d22..072d741 100644 --- a/Tests/Functional/DataProcessing/ListMenuProcessorTest.php +++ b/Tests/Functional/DataProcessing/ListMenuProcessorTest.php @@ -13,6 +13,7 @@ */ use B13\Menus\DataProcessing\ListMenu; +use TYPO3\CMS\Core\Cache\CacheDataCollector; use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder; use TYPO3\CMS\Core\Http\ServerRequest; use TYPO3\CMS\Core\Site\Entity\Site; @@ -317,6 +318,8 @@ public function processTest(array $tsfe, array $configuration, array $expected) $request = GeneralUtility::makeInstance(ServerRequest::class); $request = $request->withAttribute('site', $site); $request = $request->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_FE); + $cacheDataCollector = new CacheDataCollector(); + $request = $request->withAttribute('frontend.cache.collector', $cacheDataCollector); $GLOBALS['TYPO3_REQUEST'] = $request; $GLOBALS['TSFE'] = $this->getTypoScriptFrontendController($site, $tsfe['id']); @@ -371,6 +374,8 @@ public function menuIdTagsAreAddedToPageCache(array $tsfe, array $configuration, $request = GeneralUtility::makeInstance(ServerRequest::class); $request = $request->withAttribute('site', $site); $request = $request->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_FE); + $cacheDataCollector = new CacheDataCollector(); + $request = $request->withAttribute('frontend.cache.collector', $cacheDataCollector); $GLOBALS['TYPO3_REQUEST'] = $request; $GLOBALS['TSFE'] = $this->getTypoScriptFrontendController($site, $tsfe['id']); diff --git a/Tests/Functional/DataProcessing/TreeMenuProcessorTest.php b/Tests/Functional/DataProcessing/TreeMenuProcessorTest.php index 62d1b4f..e4149cc 100644 --- a/Tests/Functional/DataProcessing/TreeMenuProcessorTest.php +++ b/Tests/Functional/DataProcessing/TreeMenuProcessorTest.php @@ -13,6 +13,7 @@ */ use B13\Menus\DataProcessing\TreeMenu; +use TYPO3\CMS\Core\Cache\CacheDataCollector; use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder; use TYPO3\CMS\Core\Http\ServerRequest; use TYPO3\CMS\Core\Site\Entity\Site; @@ -401,6 +402,8 @@ public function processTest(array $tsfe, array $configuration, array $expected): $request = GeneralUtility::makeInstance(ServerRequest::class); $request = $request->withAttribute('site', $site); $request = $request->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_FE); + $cacheDataCollector = new CacheDataCollector(); + $request = $request->withAttribute('frontend.cache.collector', $cacheDataCollector); $GLOBALS['TYPO3_REQUEST'] = $request; $GLOBALS['TSFE'] = $this->getTypoScriptFrontendController($site, $tsfe['id']); @@ -466,6 +469,8 @@ public function menuIdTagsAreAddedToPageCache(array $tsfe, int $entryPoints, arr $request = GeneralUtility::makeInstance(ServerRequest::class); $request = $request->withAttribute('site', $site); $request = $request->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_FE); + $cacheDataCollector = new CacheDataCollector(); + $request = $request->withAttribute('frontend.cache.collector', $cacheDataCollector); $GLOBALS['TYPO3_REQUEST'] = $request; $GLOBALS['TSFE'] = $this->getTypoScriptFrontendController($site, $tsfe['id']);