1
votes

I created a new extension to add some fields to the news extension.
In the backend everything works fine, I can add values to the fields and they are correctly saved in the database.

When I clear the cache and rebuild PHP Autoload Information it show in the frontend but after some hours the new fields disappears magically.

I have created the extension with the Extension Builder and added the field manually.
I read the ProxyClass generator info a lot of times but cannot see the fail.

Looks like I need connect the class in the cache or elsewhere.
I’m really desperate with this.

ext: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 = '';

ext: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);

ext: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'
…

ext: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
                                }
                        }   
                }
        }
}

I'm using: TYPO3 9.5.22 & News 7.3.1

3
Hi, I guess you call method ExtensionManagementUtility::addToAllTCAtypes(), to add your new fields. These new fields must be in file Configuration/TCA/Overrides/tx_news_domain_model_news.php instead of ext_tables.php.Florian Rival
Thanks a lot! I cleaned ext_tables.php and move all TCA definition to Configuration/TCA/Overrides/tx_news_domain_model_news.php with ExtensionManagementUtility::addToAllTCAtypes() now it has a lot of sense to me. But now I don't see the fields neither on the backend nor on the frontend. Tried to uninstall/install/Clear Cache/Dump... Something still missingUnai Aizpurua
What a mess! After an hour checking why it didn't work, the problem was that the file had a space at the end. Now it seems that everything looks and works, to see if in a few hours it remains Working.Unai Aizpurua

3 Answers

0
votes

I guess that the problem is because you override the tx_news record type 0.

You'd better have something like this :

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
                }
            }
        }
    }
}

and then, defined a new type of record in Configuration/TCA/Overrides/tx_news_domain_model_news.php containing your new field :

$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,'
];

Have a look in news/Configuration/TCA/tx_news_domain_model_news.php

0
votes

If you want to keep record type = 0, then, I suggest you to do that :

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

And in Configuration/TCA/Overrides/tx_news_domain_model_news.php, overrides 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,'
    ]
);

An set the tt_news dependencies in ext_emconf.php :

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