TYPO3:tx_news 扩展中新字段的缓存问题

TYPO3: Caching issue with new fields in tx_news extension

我创建了一个新的扩展来向新闻扩展添加一些字段。
在后端一切正常,我可以向字段添加值,它们会正确保存在数据库中。

当我清除缓存并重建时 PHP 自动加载信息显示在前端,但几个小时后新字段神奇地消失了。

我已经使用 Extension Builder 创建了扩展并手动添加了字段。
我多次阅读 ProxyClass generator 信息,但看不到失败。

看来我需要在缓存或其他地方连接 class。
我真的很绝望。

分机:albr_news_new_fields/Classes/Domain/Model/News.php

namespace Albr\AlbrNewsNewFields\Domain\Model;
class News extends \GeorgRinger\News\Domain\Model\News {
/**
     * titulo1
     * 
     * @var string
     */
    protected $titulo1 = '';

分机:albr_news_new_fields/ext_localconf.php

defined('TYPO3_MODE') or die();

$GLOBALS['TYPO3_CONF_VARS']['EXT']['news']['classes']['Domain/Model/News'][] = 'albr_news_new_fields';

\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\Container\Container::class)
    ->registerImplementation(\GeorgRinger\News\Domain\Model\News::class,
        \Albr\AlbrNewsNewFields\Domain\Model\News::class);

分机:albr_news_new_fields/ext_tables.php

call_user_func(
    function()
    {
        \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile('albr_news_new_fields', 'Configuration/TypoScript', 'Nuevos campos tx_news');
    }
);

$tempColumns = Array (
    'titulo1' => [
        'exclude' => true,
        'label' => 'LLL:EXT:albr_news_new_fields/Resources/Private/Language/locallang_db.xlf:titulo1',
        'description' => 'LLL:EXT:albr_news_new_fields/Resources/Private/Language/locallang_db.xlf:titulo1.description',
        'config' => [
            'type' => 'input',
            'size' => 50,
            'eval' => 'trim'
…

分机:albr_news_new_fields/Configuration/Typoscript/setup.typoscript

plugin.tx_news {
        persistence {
                classes {
                        GeorgRinger\News\Domain\Model\News {
                                subclasses {
                                        # three different classes are used for each news type
                                        # 0 == default news
                                        0 = Albr\AlbrNewsNewFields\Domain\Model\News
                                }
                        }
                        Albr\AlbrNewsNewFields\Domain\Model\NewsDefault {
                                mapping {
                                        recordType = 0
                                        tableName = tx_news_domain_model_news
                                }
                        }
                        Albr\AlbrNewsNewFields\Domain\Model\News {
                                mapping {
                                        recordType = 0
                                        tableName = tx_news_domain_model_news
                                }
                        }
                }
        }
}

config.tx_extbase {
        persistence {
                classes {
                        GeorgRinger\News\Domain\Model\News {
                                subclasses {
                                        GeorgRinger\News\Domain\Model\News = Albr\AlbrNewsNewFields\Domain\Model\News
                                }
                        }
                        Albr\AlbrNewsNewFields\Domain\Model\News {
                                mapping {
                                        tableName = tx_news_domain_model_news
                                }
                        }   
                }
        }
}

我正在使用:TYPO3 9.5.22 & News 7.3.1

ext_tables.php 不应再用于 TCA 操作,请参阅 https://docs.typo3.org/m/typo3/reference-coreapi/9.5/en-us/ExtensionArchitecture/ConfigurationFiles/Index.html#ext-tables-php

另见 Configuration/TCA/Overrides/tx_news_domain_model_news.php 中的提及 https://docs.typo3.org/p/georgringer/news/master/en-us/DeveloperManual/ExtendNews/ProxyClassGenerator/Index.html

我猜问题是因为您覆盖了 tx_news 记录类型 0。

你最好有这样的东西:

plugin.tx_news {
    persistence {
        classes {
            GeorgRinger\News\Domain\Model\News {
                subclasses {
                    3 = Albr\AlbrNewsNewFields\Domain\Model\News
                }
            }
            Albr\AlbrNewsNewFields\Domain\Model\News {
                mapping {
                    recordType = 3
                    tableName = tx_news_domain_model_news
                }
            }
        }
    }
}

然后,在 Configuration/TCA/Overrides/tx_news_domain_model_news.php 中定义了一个包含新字段的新记录类型:

$GLOBALS['TCA']['tx_news_domain_model_news']['types']['3'] = [
    'showitem' => '
            --palette--;;paletteCore,title,titulo1,--palette--;;paletteSlug,teaser,
            --palette--;;paletteDate,
            bodytext,
        --div--;' . $ll . 'tx_news_domain_model_news.content_elements,
            content_elements,
        --div--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:tabs.media,
            fal_media,fal_related_files,
        --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:categories,
            categories,
        --div--;' . $ll . 'tx_news_domain_model_news.tabs.relations,
            related,related_from,
            related_links,tags,
        --div--;LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.tabs.metadata,
            --palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.palettes.editorial;paletteAuthor,
            --palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.palettes.metatags;metatags,
            --palette--;' . $ll . 'tx_news_domain_model_news.palettes.alternativeTitles;alternativeTitles,
        --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:language,
            --palette--;;paletteLanguage,
        --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:access,
            --palette--;;paletteHidden,
            --palette--;;paletteAccess,
        --div--;' . $ll . 'notes,
            notes,
        --div--;LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.tabs.extended,'
];

看看news/Configuration/TCA/tx_news_domain_model_news。php

如果你想保留 record type = 0,那么,我建议你这样做:

plugin.tx_news {
    persistence {
        classes {
            Albr\AlbrNewsNewFields\Domain\Model\News {
                mapping {
                    recordType = 0
                    tableName = tx_news_domain_model_news
                }
            }
        }
    }
}

并且在 Configuration/TCA/Overrides/tx_news_domain_model_news.php 中覆盖 type = 0 :

$GLOBALS['TCA']['tx_news_domain_model_news']['types']['0'] = array_replace_recursive(
    $GLOBALS['TCA']['tt_content']['types']['0'],
    [
        'showitem' => '
                --palette--;;paletteCore,title,titulo1,--palette--;;paletteSlug,teaser,
                --palette--;;paletteDate,
                bodytext,
            --div--;' . $ll . 'tx_news_domain_model_news.content_elements,
                content_elements,
            --div--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:tabs.media,
                fal_media,fal_related_files,
            --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:categories,
                categories,
            --div--;' . $ll . 'tx_news_domain_model_news.tabs.relations,
                related,related_from,
                related_links,tags,
            --div--;LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.tabs.metadata,
                --palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.palettes.editorial;paletteAuthor,
                --palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.palettes.metatags;metatags,
                --palette--;' . $ll . 'tx_news_domain_model_news.palettes.alternativeTitles;alternativeTitles,
            --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:language,
                --palette--;;paletteLanguage,
            --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:access,
                --palette--;;paletteHidden,
                --palette--;;paletteAccess,
            --div--;' . $ll . 'notes,
                notes,
            --div--;LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.tabs.extended,'
    ]
);

在 ext_emconf.php 中设置 tt_news 依赖项:

$EM_CONF[$_EXTKEY] = [
    ...
    'constraints' => [
        'depends' => [
            'typo3' => '9.5.0-9.5.99',
            'tt_news' => '7.3.1-7.3.99',
        ],
        'conflicts' => [],
        'suggests' => [],
    ],
];