typo3typo3-extensionstypo3-tca

How to add fields to the `searchFields` in TYPO3's TCA


I have an extension that extends an existing table by adding some fields. What is the correct way to make those fields searchable, too?

Because I didn't find any documentation or method in the ExtensionManagementUtility and there is no setting like searchable = true in the field's search property I simply added my fields to the $GLOBALS['TCA']'s searchFields that way:

$GLOBALS['TCA'][$table]['ctrl']['searchFields'] = $GLOBALS['TCA'][$table]['ctrl']['searchFields'] . ', my_field_1, my_field_2';

Is this the only and best way to do it?


Solution

  • In the TYPO3 Versions 4.6 - 10.4 there is the hook to manipulate the searchfields of a table:

    $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['mod_list']['getSearchFieldList']
    

    This hook has been removed in TYPO3 11.0.

    See: https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/11.0/Breaking-92128-DatabaseRecordListDropHookToModifySearchFields.html

    To use a hook for searchfield manipulation is kind of making the thing more complicated than necessary.

    Not sure if there is another way since TYPO3 11.0.

    So the easiest way is to add a PHP-file with the name of the table you want to manipulate in your EXT:Configuration/TCA/Overrides folder. And add the new searchfields like you described.

    There i would prefer to write it a little shorter like:

    $GLOBALS['TCA'][$table]['ctrl']['searchFields'] .= ', my_field_1, my_field_2';