TYPO3 TCA type "select" performance issue

988 views Asked by At

Is there a possibility to use the TCA field type "select" for a table which has thousands of entries?

The selectbox with the entries shouldn't be displayed (else the record loads minutes or you get a memory limit or max execution time error), but something like a search field (like the existing wizard "suggest") or a record browser (like TCA type "group" has).

4

There are 4 answers

0
Sven On BEST ANSWER

It's possible with TCA type "group" and (very important!) setting foreign_table:

'config' => [
    'type' => 'group',
    'internal_type' => 'db',
    'allowed' => 'fe_users',
    'foreign_table' => 'fe_users'
],

From offical documentation (https://docs.typo3.org/typo3cms/TCAReference/ColumnsConfig/Type/Group.html#foreign-table):

foreign_table: This property does not really exist for group-type fields. It is needed as a workaround for an Extbase limitation. It is used to resolve dependencies during Extbase persistence. It should hold the same values as property allowed. Notice that only one table name is allowed here in contrast to the property allowed itself.

5
Claus Due On

Look for the group with internal_type set to db as an alternative to the select type; which does precisely what you need here. This is the only type of field which allows your specific use case.

Alternatives include using a input type for the field and fitting it with wizards, then configure the wizard so it replaces the original field and only the wizard is shown.

Don't forget to check your SQL keys for the table you're listing. If your listing uses an un-indexed column you can decrease the time to an extreme degree by simply adding an SQL index for the column(s) you use.

3
jokumer On

I'm using the old TCA field type 'group', which solves this behavior also in TYPO3 CMS 8

'my_select_field' => [
    'label' => 'My select field',
    'config' => [
        'type' => 'group',
        'internal_type' => 'db',
        'allowed' => 'my_foreign_table_name',
        'size' => 1,
        'minitems' => 0,
        'maxitems' => 1,
        'suggestOptions' => [
            'default' => [
                'pidList' => 0,
                'searchCondition' => 'hidden=0',
                'searchWholePhrase' => 1
            ]
        ]
    ]
]
0
Sven On

One option is to set the field to "readonly". Of course then one can't edit this field in TYPO3 BE, but if the data is coming e.g. from an external source, this is a disadvantage I can live with.

'config' => [
    'type' => 'select',
    'foreign_table' => 'fe_users',
    'size' => 1,
    'minitems' => 1,
    'maxitems' => 2, // it has to be > 1 because else a selectbox is rendered
    'readOnly' => 1, // readOnly because of performance issues
],