TYPO3 Media-Emelent own field

703 Views Asked by At

is it possible to extend the media type in my typo3 extension? Default fields are alternative, title, desription. How can i add a own field?

$GLOBALS['TCA']['tt_content']['types']['my_slider'] = [
        'showitem'         => '
                --palette--;' . $frontendLanguageFilePrefix . 'palette.general;general,
                --palette--;' . $languageFilePrefix . 'tt_content.palette.mediaAdjustments;mediaAdjustments,
                pi_flexform,
            --div--;' . $customLanguageFilePrefix . 'tca.tab.sliderElements,
                 assets
        ',
        'columnsOverrides' => [
            'media' => [
                'label'  => $languageFilePrefix . 'tt_content.media_references',
                'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig('media', [
                    'appearance'    => [
                        'createNewRelationLinkTitle' => $languageFilePrefix . 'tt_content.media_references.addFileReference'
                    ],
                    // custom configuration for displaying fields in the overlay/reference table
                    // behaves the same as the image field.
                    'foreign_types' => $GLOBALS['TCA']['tt_content']['columns']['image']['config']['foreign_types']

                ], $GLOBALS['TYPO3_CONF_VARS']['SYS']['mediafile_ext'])
            ]
        ]
    ];
1

There are 1 best solutions below

2
Bernd Wilke πφ On

if you analyze the datastructure of your TYPO3 database you will find: those fields (title and alternative) are not fields in the table sys_file but in sys_file_metadata (and in sys_file_reference for overwriting them on a specific usage)

With that knowledge you can add your fields to these tables and give them a proper rendering and behaviour.


Adding the fields to sys_file_metadata will make them available for every file as default values if the fiel is used anywhere.
If you want these fields appear only at special usage you need to set the fields only for the table sys_file_reference which is used only for relations between a file and it's usage. AND you need to set conditions to show the fields only if your content elements use a file. This condition might be a litte complicated. if you use inidvidual tables the condition could be used the usage of this foreign_table, if you use tt_content records you also need to include the CTypeof the record in the condition. Probably you will need an userfunc.
Or you have an unique fieldname?