You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Typo3 v11.5.8与tx_news 9.3.1:自定义字段仅清除缓存后才可在详情页显示的问题求助

解决TYPO3 v11+tx_news自定义类型详情页需清缓存才显示的问题

我之前在升级TYPO3到v11时也碰到过类似的缓存问题,结合你的代码和版本环境,大概率是Extbase在v11中对类映射、缓存清理的机制有了更严格的要求。下面是几个针对性的解决思路:

1. 修复Extbase持久化配置的继承关系

你的Classes.php配置里,子类的映射可以补充明确的继承声明,让Extbase更清晰地识别父子类关系:

return [
    \GeorgRinger\News\Domain\Model\News::class => [
        'subclasses' => [
            3 => \Albr\Quincena\Domain\Model\Eventos::class,
            4 => \Albr\Quincena\Domain\Model\Informacion::class,
        ]
    ],
    // ... 保留原有默认类型配置
    \Albr\Quincena\Domain\Model\Eventos::class => [
        'tableName' => 'tx_news_domain_model_news',
        'recordType' => 3,
        'inheritance' => [
            'parent' => \GeorgRinger\News\Domain\Model\News::class
        ]
    ],
    \Albr\Quincena\Domain\Model\Informacion::class => [
        'tableName' => 'tx_news_domain_model_news',
        'recordType' => 4,
        'inheritance' => [
            'parent' => \GeorgRinger\News\Domain\Model\News::class
        ]
    ],
];

另外可以在Install Tool的「Configuration」页面搜索GeorgRinger\News\Domain\Model\News,确认你的自定义recordType(3、4)是否被正确加载,没有被tx_news的默认配置覆盖。

2. 补充记录保存时的缓存清理钩子

TYPO3 v11的缓存自动清理逻辑对自定义类型的覆盖可能不够,你可以添加一个钩子,在保存news记录时清理对应Extbase对象缓存:

首先创建钩子类ext:quincena/Classes/Hooks/CacheHook.php:

namespace Albr\Quincena\Hooks;

use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class CacheHook {
    public function clearCache(array &$params): void {
        $cacheManager = GeneralUtility::makeInstance(CacheManager::class);
        // 清理Extbase对象缓存和页面缓存
        $cacheManager->flushCachesInGroup('extbase');
        $cacheManager->flushCachesInGroup('pages');
    }
}

然后在ext:quincena/ext_localconf.php注册钩子:

$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearCachePostProc'][] = 
    \Albr\Quincena\Hooks\CacheHook::class . '->clearCache';

3. 优化TCA配置的冗余代码

你的TCA配置里有重复赋值的问题,虽然不影响功能,但可能导致潜在的混淆,建议合并优化:

// 添加自定义类型选项
$GLOBALS['TCA']['tx_news_domain_model_news']['columns']['type']['config']['items'][] = 
    ['Evento', 3, 'ext-news-type-evento'];
$GLOBALS['TCA']['tx_news_domain_model_news']['columns']['type']['config']['items'][] = 
    ['Informacion', 4, 'ext-news-type-informacion'];

// 设置类型图标
$GLOBALS['TCA']['tx_news_domain_model_news']['ctrl']['typeicon_classes'][3] = 'ext-news-type-evento';
$GLOBALS['TCA']['tx_news_domain_model_news']['ctrl']['typeicon_classes'][4] = 'ext-news-type-informacion';

4. 自定义DataProvider确保模型正确实例化

tx_news v9在详情页加载模型时,可能没有自动根据recordType切换到你的子类,你可以自定义DataProvider强制处理:

创建ext:quincena/Classes/Domain/DataProvider/CustomNewsDataProvider.php:

namespace Albr\Quincena\Domain\DataProvider;

use GeorgRinger\News\Domain\DataProvider\NewsDataProvider;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;

class CustomNewsDataProvider extends NewsDataProvider {
    protected ObjectManagerInterface $objectManager;

    public function __construct(ObjectManagerInterface $objectManager) {
        $this->objectManager = $objectManager;
        parent::__construct($objectManager);
    }

    public function getNewsItem(): ?\GeorgRinger\News\Domain\Model\News {
        $newsItem = parent::getNewsItem();
        if (!$newsItem) return null;

        // 根据recordType切换到自定义子类
        switch ($newsItem->getType()) {
            case 3:
                $newsItem = $this->objectManager->get(\Albr\Quincena\Domain\Model\Eventos::class, $newsItem->getUid());
                break;
            case 4:
                $newsItem = $this->objectManager->get(\Albr\Quincena\Domain\Model\Informacion::class, $newsItem->getUid());
                break;
        }
        return $newsItem;
    }
}

然后在ext_localconf.php替换默认的DataProvider:

$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['news']['dataProviders']['news'] = 
    \Albr\Quincena\Domain\DataProvider\CustomNewsDataProvider::class;

优先尝试前两个方案,尤其是缓存清理钩子和Extbase配置优化,这是v11升级后最常见的缓存适配点。

内容的提问来源于stack exchange,提问作者Unai Aizpurua

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.28 18:58:12