我的 T3 分机中有以下行
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['headerNoCache']['XY'] = \Namespace\Folder\Hooks\Class::class.'->headerNoCache ';
这不再适用于 TYPO3 版本 12。
如果没有 Service.yaml 中的条目,如何在 TYPO3 中执行此操作?我必须建立这样的东西:
public function __invoke(ShouldUseCachedPageDataIfAvailableEvent | ModifyUrlForCanonicalTagEvent $event): void
{
$href = $event->getUrl();
$this->generateCanonical($href);
$event->setUrl($href);
$noCache = $event->getRequest()->getQueryParams();
if ($this->canonicalActive($noCache) &&
( $this->canonicalForKurs($noCache)
|| $this->canonicalForDozent($noCache)
|| $this->canonicalForAussenstelle($noCache)
|| $this->canonicalForHaus($noCache)
|| $this->canonicalForRaum($noCache)
)) {
$event->shouldUseCachedPageData(false);
}
}
但是它说
Call to undefined method TYPO3\CMS\Seo\Event\ModifyUrlForCanonicalTagEvent::shouldUseCachedPageData()
您允许在此处调用两个不同的事件(ShouldUseCachedPageDataIfAvailableEvent | ModifyUrlForCanonicalTagEvent)。
调用方法时需要先检查当前事件的类型,因为每个事件的方法都不同。
最好为此创建两个不同的事件侦听器,而不是组合一个。