TCA Definition

This chapter explains how to create a field that makes it possible to create relations to files.

Changed in version 12.0: For TYPO3 v11 and bellow the API function ExtensionManagementUtility::getFileFieldTCAConfig() was used to create a TCA configuration suitable to handle files. This function has been deprecated with the introduction of the new field type File.

The TCA field type File can be used to provide a field in which files can be referenced and or uploaded:

EXT:some_extension/Configuration/TCA/my_table.php
return [
    'columns' => [
        'my_media_file' => [
            'label' => 'My image',
            'config' => [
                'type' => 'file',
                'allowed' => 'common-media-types'
            ],
        ],
    ],
    // ...
];

On the database side, the corresponding field needs just store an integer, as is usual for relations field:

EXT:some_extension/ext_tables.sql
CREATE TABLE my_table (
   my_media_file int(11) unsigned DEFAULT '0' NOT NULL,
);

The property appearance can be used to specify if a file upload button and file by URL button (Vimeo, Youtube) should be displayed.

Example:

EXT:some_extension/Configuration/TCA/Overrides/my_table.php
$GLOBALS['TCA']['my_table']['columns']['my_media_file']['config']['appearance'] = [
    'fileUploadAllowed' => false,
    'fileByUrlAllowed' => false,
];

This will suppress two buttons for upload and external URL and only leave the button Create new relation.

Migration from ExtensionManagementUtility::getFileFieldTCAConfig

// Before
'columns' => [
    'image' => [
        'label' => 'My image',
        'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
            'image',
            [
                'maxitems' => 6,
            ],
            $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
        ),
    ],
],

// After
'columns' => [
    'image' => [
        'label' => 'My image',
        'config' => [
            'type' => 'file',
            'maxitems' => 6,
            'allowed' => 'common-image-types'
        ],
    ],
],