typo3fluidextbaseflexform

Receiving and Displaying data of referenced record in Extbase/Fluid


Situation:

I have an (Extbase/Fluid) extension which stores a single DB reference from a specific database table (tt_address).

<internal_type>db</internal_type>
<allowed>tt_address</allowed>

Intention: I want to display data (some db fields) from this reference (only) in the frontend.

Problem: How do I get the stored reference in Extbase/Fluid and how do I get access to the data fields? in the frontend?

Typoscript:

    tt_content {
      addresscontainer = FLUIDTEMPLATE
      addresscontainer {
    
        templateName = AddressContainer
        templateRootPaths {
          10 = EXT:xyz/Resources/Private/Partials/ContentElements/
        }
        partialRootPaths {
          10 = EXT:xyz/Resources/Private/Partials
        }
        dataProcessing {
          1 = TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor
          1 {
              options {
                    if.isTrue.field = records
                }
                table = tt_address
                #where = uid = 5
    
                pidInList = 20
                as = address_record
          }
        }
      }
    }

Flexform / XML:

    <?xml version="1.0" encoding="utf-8" standalone="yes" ?>
    <T3DataStructure>
        <sheets>
            <sDEF>
                <ROOT>
                    <TCEforms>
                        <sheetTitle>TT-Address - Single Address</sheetTitle>
                    </TCEforms>
                    <type>array</type>
                    <el>
                        <faddress>
                            <TCEforms>
                                <label>Single Address</label>
                                <config>
                                    <type>group</type>
                                    <internal_type>db</internal_type>
                                    <allowed>tt_address</allowed>
                                    <size>1</size>
                                    <maxitems>1</maxitems>
                                    <minitems>0</minitems>
                                    <show_thumbs>1</show_thumbs>
                                </config>
                            </TCEforms>
                        </faddress>
                    </el>
                </ROOT>
            </sDEF>
        </sheets>
    </T3DataStructure>

HTML:

<strong>{address_record.data.company}</strong><br>

The code is basically working. However, it fetches all records which are stored in the tt_address table. I want the one which was assigend in the backend only.

I hope my intention is clear.

Thank you in advance!


Solution

  • If you want to access the FlexForm value from your plugin or content element you can do that with the data type flexform:

    dataProcessing {
      10 = TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor
      10 {
        table = tt_address
        pidInList = 20
        uidInList.data = flexform:pi_flexform:faddress
      }
    }
    

    See the TypoScript Reference for details on the data type flexform.

    If you're using TYPO3 v11, you can also use the brand new FlexForm Data Processor.