lufi
lufi

Reputation: 670

Custom TCA Fields not visible in Frontend

I've created a Backend Extension and extended fe_user by 4 additional fields.

I am Using TYPO3 7.6.13.

The 4 custom fields are visible in backendlists, but not the fields are not available in frontend.

Is there any "special" list I need to extend with my fields? My TCA Configuration as follows.

ExtensionManagementUtility::addTCAcolumns('fe_users', $temporaryColumns);
ExtensionManagementUtility::addToAllTCAtypes('fe_users', 'field1', '', 'after:image');
ExtensionManagementUtility::addToAllTCAtypes('fe_users', 'field2', '', 'after:field1');
ExtensionManagementUtility::addToAllTCAtypes('fe_users', 'field3', '', 'after:field2');
ExtensionManagementUtility::addToAllTCAtypes('fe_users', 'field4', '', 'after:field3');
ExtensionManagementUtility::addToAllTCAtypes(
    'fe_users',
    'field1, field2, field3, field4'
);

Is there more todo or did I ran in some sort of bug?

Upvotes: 0

Views: 1563

Answers (2)

Christoph Bessei
Christoph Bessei

Reputation: 111

To extend an existing extbase model the folllowing steps are needed:

  • Add the fields to your database in ext_tables.sql
  • Add the fields to TCA in Configuration/TCA/Overrides/table_name.php

This should be enough to use the fields inside the TYPO3 backend. For frontend rendering your need two more steps:

  • Extend the Extbase model (Property, Getter and Setter)
  • Tell extbase to use your new model with TypoScript: config.tx_extbase.persistence.classes

As far as I understand your did the first 3 steps, but maybe missed the last one?

Full example (ext_typoscript_setup.txt, normal TypoScript file should also work):

config.tx_extbase {
    persistence {
        classes {
            TYPO3\CMS\Extbase\Domain\Model\FrontendUser {
                subclasses {
                    0 = YourVendor\YourextNamespace\Domain\Model\YourClass
                }
             }
        }
    }
} 

This should be enough for many tables, but fe_users uses the recordType field. To configure this you need the following TypoScript snippet (same file as the config.tx_extbase config):

config.tx_extbase {
    persistence {
        classes {
         YourVendor\YourextNamespace\Domain\Model\YourClass {
            mapping {
               tableName = fe_users
               recordType = 0
            }
        }
    }
}

This forces extbase to ignore the recordType and always use your model.

Documentation/Full example (including recordType explanation): https://docs.typo3.org/typo3cms/ExtbaseFluidBook/6-Persistence/5-modeling-the-class-hierarchy.html

Upvotes: 2

Stefan Padberg
Stefan Padberg

Reputation: 527

You have to add the fields to the model. In your domain you will have a fe_user repository which will be mapped to the real fe_user table.

If you add fields to fe_user you have to add them also to your fe_user model.

Did you think about that?

Upvotes: 0

Related Questions