Fetch custom domain model data via TypoScript

Hey all,

I’m having a bit of trouble using the TypoScript database-query to fetch content from a custom domain model table.

I have a content element CtaWithContactPerson, which should display a heading, text and one or more contact persons. For the contact persons I’m using an inline type field:

// simplified field
'contact_persons' => [
        'label' => 'Ansprechpartner',
        'config' => [
            'type' => 'inline',
            "foreign_table" => "tt_content_contact_persons",
            "foreign_field" => "tt_content",
            'foreign_sortby' => 'sorting',
        ],
    ],

I store the inline elements in a new table, tt_content_contact_persons.
Such an inline element has these columns:

// simplified columns
'columns' => [
        'bodytext' => [
            'label' => 'Text',
            'config' => [
                'type' => 'text',
            ],
        ],
        'contact_person' => [
            'label' => 'Ansprechpartner',
            'config' => [
                'type' => 'group',
                'allowed' => 'tx_website_domain_model_teammember',
                "minitems" => 1,
                "maxitems" => 1,
            ],
        ],
    ],

There, I can select one of the team members from the table tx_website_domain_model_teammember. Those are managed on root level in a backend module. That works fine.

But now I want to display that contact person / team member in my content element, so I need to fetch it beforehand using TypoScript.

cta_with_contact_person =< lib.contentElement
cta_with_contact_person {
    templateName = CtaWithContactPerson
    dataProcessing {
        10 = database-query
        10 {
            table = tt_content_contact_persons
            pidInList.field = pid
            orderBy = sorting
            where {
                data = field:uid
                intval = 1
                wrap = tt_content=|
            }
            as = contactPersons
            dataProcessing {
                10 = database-query
                10 {
                    table = tx_website_domain_model_teammember
                    orderBy = sorting
                    where {
                        data = field:contact_person
                        intval = 1
                        wrap = uid=|
                    }
                    as = person
                    dataProcessing {
                        10 = files
                        10 {
                            references.fieldName = image
                            sorting = title
                            sorting.direction = descending
                            as = image
                        }
                    }
                }
            }
        }
    }
}

The issue is that the person array is empty. Something is not configured correctly when fetching from tx_website_domain_model_teammember. I am trying to get the team member by uid, which is stored in the field contact_person.

Content element variable dump:
Screenshot_5

What did I do wrong here? Been trying to fix this for 3 hours. Cheers!

Hi J D!

It looks like you may be missing pidInList for the query on the tx_website_domain_model_teammember table. I’ve forgotten this exact thing multiple times myself.

If it isn’t set pidInList will default to the PID of the current page. Since you’re setting it for tt_content_contact_persons, I guess the records aren’t stored on the same page.

PS! To simplify your TypoScript, try using uidInList rather than the five-line where clause. Like this: uidInList.field = uid.

— Mathias

Thanks for your tips!
I adjusted my TypoScript and now it works:

table = tx_website_domain_model_teammember
orderBy = sorting
pidInList = 0
uidInList.field = contact_person
as = person
1 Like

Hooray! Great to hear!

— Mathias

Hi again,

I’m stuck on a different issue now which involves the same code.

I have added the functionality to manage projects and display them as list/detail views. You can also add content elements to a project - just like with tx_news.

The issue is that when I use the previously mentioned content element CtaWithContactPerson on a project detail page, the contact persons are not fetched. I checked the database entries to see if the id’s/pid’s and relations matched and it looked all good to me. Only setting pidInList and uidInList manually in my TypoScript got me the correct results.

Below is my current TypoScript. This works on normal pages, but not on detail pages rendered by a plugin and contactPersons will be an empty array.

    cta_with_contact_person =< lib.contentElement
    cta_with_contact_person {
        templateName = CtaWithContactPerson
        dataProcessing {
            10 = database-query
            10 {
                table = tt_content_contact_persons
                orderBy = sorting
                as = contactPersons
                dataProcessing {
                    10 = database-query
                    10 {
                        table = tx_website_domain_model_teammember
                        orderBy = sorting
                        pidInList = 0
                        uidInList.field = contact_person
                        as = person
                    }
                }
            }
        }
    }

If it helps, here are the relevant database columns:

CREATE TABLE tt_content (
    /* reference to multiple tt_content_contact_persons */
    contact_persons int(11) unsigned DEFAULT '0' NOT NULL,
    reference_project int(11) unsigned DEFAULT '0' NOT NULL,
);

CREATE TABLE tt_content_contact_persons (
    /* reference to tx_website_domain_model_teammember */
    contact_person int(11) unsigned DEFAULT '0' NOT NULL,
    tt_content int(11) unsigned DEFAULT '0' NOT NULL,
);

CREATE TABLE tx_website_domain_model_teammember (
    /* some unrelated fields... */
);

CREATE TABLE tx_website_domain_model_referenceproject (
    content_elements int(11) unsigned DEFAULT '0' NOT NULL,
);

Thank you in advance for helping!