typo3fal

TYPO3: add maxitems = 1 to an image selection for a backend module


I use the following code to make an image selection available in the backend:
(TYPO3 docs - inline - File Abstraction Layer)

'image' => [
    'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.images',
    'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
        'image',
        [
            'appearance' => [
                'createNewRelationLinkTitle' => 'LLL:EXT:cms/locallang_ttc.xlf:images.addFileReference'
            ],
            // custom configuration for displaying fields in the overlay/reference table
            // to use the image overlay palette instead of the basic overlay palette
            'overrideChildTca' => [
                'types' => [
                    '0' => [
                        'showitem' => '
                            --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
                            --palette--;;filePalette'
                    ],
                    \TYPO3\CMS\Core\Resource\File::FILETYPE_TEXT => [
                        'showitem' => '
                            --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
                            --palette--;;filePalette'
                    ],
                ],
            ],
        ],
        $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
    ),
],

I want to limit the selection to 1 item which should be:
TYPO3 dosc - maxitems option

image => [
    'config' => [
        'maxitems' => 1,
    ],
],

I cannot find how to add that ... all I tried gives errors


Solution

  • Sometimes, you just have to find the matching part of documentation...

    File abstraction layer (FAL)

    The API call is \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(). The first argument is the name of the current field, the second argument is an override configuration array, (...)

    So it should do with overriding a part of the generated configuration by:

    'image' => [
        'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.images',
        'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
            'image',
            [
                'maxitems' => 1
            ]
        )
    ]