Search code examples
typo3typo3-9.x

Override TCA config for imageManipulation/crop for only one content type (CType)


I have three type of content elements (tt_content|types) which all use an image-column with each one FAL-relations for one image.

I'd like to use for 2 content elements the type = 'imageManipulation' (Docs) with 2 different configurations and for one just the image as it is.

Since the type = 'imageManipulation' is defined normally for sys_file_reference, so for all usages.

Is it possible with TCA overrides to archive different configurations for different content elements?

I tried a combination of columnsOverrides and overrideChildTca, but this doesn't work in the moment:

<?php
defined('TYPO3_MODE') or die();

(function () {
    if (is_array($GLOBALS['TCA']['tt_content']['types']['mask_teaser_hero'])) {
        $GLOBALS['TCA']['tt_content']['types']['mask_teaser_hero']['columnsOverrides'] = [
            'tx_maskproject_teaserimage' => [
                'config' => [
                    'overrideChildTca' => [
                        'columns' => [
                            'crop' => [
                                'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_tca.xlf:sys_file_reference.crop',
                                'config' => [
                                    'type' => 'imageManipulation',
                                    'cropVariants' => [
                                        'mobile' => [
                                            'title' => 'Mobile',
                                            'selectedRatio' => '4:3',
                                            'allowedAspectRatios' => [
                                                '4:3' => [
                                                    'title' => 'LLL:EXT:lang/Resources/Private/Language/locallang_wizards.xlf:imwizard.ratio.4_3',
                                                    'value' => 4 / 3
                                                ],
                                            ],
                                        ],
                                        'desktop' => [
                                            'title' => 'Desktop',
                                            'selectedRatio' => '16:9',
                                            'allowedAspectRatios' => [
                                                '16:9' => [
                                                    'title' => 'LLL:EXT:lang/Resources/Private/Language/locallang_wizards.xlf:imwizard.ratio.16_9',
                                                    'value' => 16 / 9
                                                ],
                                            ],
                                        ],
                                    ]
                                ],
                            ],
                        ]
                    ],
                ]
            ]
        ];
    }

})();

I first thought about Typoscript TCEFORM: https://metinyilmaz.de/artikel/typo3-image-cropvariants/

But this would also appear in each content element.


Solution

  • I found the mistake. The TCA override is correct. But the type was not.

    I use EXT:mask_export for the content elements. In the example from the question I override the content elements which EXT:mask adds. But the exported content elements are different content elements.

    The correct one is:

    <?php
    defined('TYPO3_MODE') or die();
    
    (function () {
        if (is_array($GLOBALS['TCA']['tt_content']['types']['myextname_teaser_hero'])) {
            $GLOBALS['TCA']['tt_content']['types']['myextname_teaser_hero']['columnsOverrides'] = [
                'tx_myextname_teaserimage' => [
                    'config' => [
                        'overrideChildTca' => [
                            'columns' => [
                                'crop' => [
                                    'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_tca.xlf:sys_file_reference.crop',
                                    'config' => [
                                        'type' => 'imageManipulation',
                                        'cropVariants' => [
                                            'mobile' => [
                                                'title' => 'Mobile',
                                                'selectedRatio' => '4:3',
                                                'allowedAspectRatios' => [
                                                    '4:3' => [
                                                        'title' => 'LLL:EXT:lang/Resources/Private/Language/locallang_wizards.xlf:imwizard.ratio.4_3',
                                                        'value' => 4 / 3
                                                    ],
                                                ],
                                            ],
                                            'desktop' => [
                                                'title' => 'Desktop',
                                                'selectedRatio' => '16:9',
                                                'allowedAspectRatios' => [
                                                    '16:9' => [
                                                        'title' => 'LLL:EXT:lang/Resources/Private/Language/locallang_wizards.xlf:imwizard.ratio.16_9',
                                                        'value' => 16 / 9
                                                    ],
                                                ],
                                            ],
                                        ]
                                    ],
                                ],
                            ]
                        ],
                    ]
                ]
            ];
        }
    
    })();