TCA - show tt_address company as a select field in custom content element

199 Views Asked by At

i have a custom package with a custom content element. The data (header + bodytext) of the custom element is stored in tt_content. This content element now needs a connection to a record of tt_address. Therefore i extendet tt_content with a field named address_uid.

My idea is to load all records (respectively the field 'company') from the table tt_address to a select field in a palette. The user can select a company and add header and bodytext and save the uid of the selected addressrecord to tt_content.

How can this be realized, in particular reading and displaying the data from tt_address.

THX for your supprt mimii

2

There are 2 best solutions below

0
On

For such cases, DataProcessors are your friend.

You can add a DatabaseQueryProcessor to the TypoScript of your content element.

tt_content {
    your_ce =< lib.contentElement
    your_ce {
        # ... template and so on

        dataProcessing.10 = TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor
        dataProcessing.10 {
            if.isTrue.field = address_uid
            table = tt_address
            uidInList.field = address_uid
            as = company
        }
    }
}
0
On

The mechanism for this is called database relation.

although it might be only an integer field in the database, the TYPO3 configuration (TCA) includes more than that and will give you the complete mechanism.

More Information about the configuration (syntax and options) can be found in the manual

If you think it is to difficult to gather all necessary options you can get help with the extension builder, an extension where you build your relation and models interactive and the code is generated.
Either you build an extension-stub with it to fill the remaining logic or you copy parts of the code into your own extension.