-->

How to add cropVariants to an image field in TYPO3

2019-05-31 10:03发布

问题:

I can override the cropVaraints for an image field in TCA like this:

'columnsOverrides' => [
    'image' => [
        'label' => 'LLL:EXT:myext/Resources/Private/Language/locallang_be.xlf:general.field.image',
        'config' => [
            'overrideChildTca' => [
                'columns' => [
                    'crop' => [
                        'config' => [
                            'cropVariants' => [
                                'default' => [
                                    'title' => 'LLL:EXT:myext/Resources/Private/Language/locallang_be.xlf:wizard.banner.title',
                                    'allowedAspectRatios' => [
                                        '2:1' => [
                                            'title' => 'LLL:EXT:myext/Resources/Private/Language/locallang_be.xlf:field.banner.image-crop.ratio',
                                            'value' => 2 / 1
                                        ],
                                    ],
                                ],
                            ],
                        ],
                    ],
                ],
            ],
        ],
    ],
],

I tryed to adabt this to flexform - but without any success. So what I need is something like this (but working :-) )

<foreign_selector_fieldTcaOverride type="array">
    <config>
        <appearance>
            <elementBrowserType>file</elementBrowserType>
            <elementBrowserAllowed>jpg,png</elementBrowserAllowed>
        </appearance>
        <overrideChildTca>
            <columns>
                <crop>
                    <config>
                        <cropVariants>
                            <default>
                                <title>Blubber</title>
                                <allowedAspectRatios>
                                    <test>
                                        <title>2:1</title>
                                        <value>2 / 1</value>
                                    </test>
                                </allowedAspectRatios>
                            </default>
                        </cropVariants>
                    </config>
                </crop>
            </columns>
        </overrideChildTca>
    </config>
</foreign_selector_fieldTcaOverride>

Does anybody did that before?

If it is not possible, maybe I can get arround the flexform? I currently have a gridelement with an Image field.

[UPDATE] As @fnagel pointed out it should be possible with overriding the default, so I tried to put the following into my Overrides/sys_file_reference.php - but it has no effect - I could even not find that default definition in TCA-Inspector...

$GLOBALS['TCA']['sys_file_reference']['columns']['crop']['config‌']['cropVariants‌​']['default'] = [
    'title' => 'LLL:EXT:al_template/Resources/Private/Language/locallang_be.xlf:wizard.gallery.title',
    'allowedAspectRatios' => [
        'NaN' => [
            'title' => 'LLL:EXT:al_template/Resources/Private/Language/locallang_be.xlf:field.gallery.image-crop.ratio',
            'value' => 0.0
        ],
    ],
];

writing ot as has also no effect...

 \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule(
    $GLOBALS['TCA']['sys_file_reference'],
    [
        'columns' =>[
            'crop' => [
                'config‌' => [
                    'cropVariants‌​' => [
                        'default'=> [
                            'title' => 'LLL:EXT:al_template/Resources/Private/Language/locallang_be.xlf:wizard.gallery.title',
                            'allowedAspectRatios' => [
                                'NaN' => [
                                    'title' => 'LLL:EXT:al_template/Resources/Private/Language/locallang_be.xlf:field.gallery.image-crop.ratio',
                                    'value' => 0.0
                                ],
                            ],
                        ],
                    ],
                ],
            ],
        ],
    ]
);

Anybody with a successfull setup for that?

回答1:

To allow image manipulation in a flexform you have to enable it via overrideChildTca property.

Example flexform:

        <background_image type="array">
            <TCEforms>
                <label>LLL:EXT:myext/Resources/Private/Language/Backend.xlf:background_image
                </label>
                <config>
                    <type>inline</type>
                    <minitems>1</minitems>
                    <maxitems>1</maxitems>
                    <appearance type="array">
                        <createNewRelationLinkTitle>LLL:EXT:cms/locallang_ttc.xlf:media.addFileReference
                        </createNewRelationLinkTitle>
                        <enabledControls type="array">
                            <delete>1</delete>
                            <dragdrop>1</dragdrop>
                            <hide>1</hide>
                            <info>1</info>
                            <localize>1</localize>
                        </enabledControls>
                        <headerThumbnail type="array">
                            <field>uid_local</field>
                            <height>45c</height>
                            <width>45</width>
                        </headerThumbnail>
                        <useSortable>1</useSortable>
                        <showAllLocalizationLink>0</showAllLocalizationLink>
                        <showPossibleLocalizationRecords>0</showPossibleLocalizationRecords>
                        <showRemovedLocalizationRecords>0</showRemovedLocalizationRecords>
                        <showSynchronizationLink>0</showSynchronizationLink>
                    </appearance>
                    <behaviour type="array">
                        <localizationMode>select</localizationMode>
                        <localizeChildrenAtParentLocalization>1</localizeChildrenAtParentLocalization>
                    </behaviour>
                    <foreign_field>uid_foreign</foreign_field>
                    <foreign_label>uid_local</foreign_label>
                    <foreign_match_fields type="array">
                        <fieldname>media</fieldname>
                    </foreign_match_fields>
                    <foreign_selector>uid_local</foreign_selector>
                    <foreign_selector_fieldTcaOverride type="array">
                        <config type="array">
                            <appearance type="array">
                                <elementBrowserAllowed></elementBrowserAllowed>
                                <elementBrowserType>file</elementBrowserType>
                            </appearance>
                        </config>
                    </foreign_selector_fieldTcaOverride>
                    <foreign_sortby>sorting_foreign</foreign_sortby>
                    <foreign_table>sys_file_reference</foreign_table>
                    <foreign_table_field>tablenames</foreign_table_field>
                    <overrideChildTca>
                        <types type="array">
                            <numIndex index="0" type="array">
                                <showitem>
                                    --palette--;LLL:EXT:lang/Resources/Private/Language/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
                                    --palette--;;filePalette
                                </showitem>
                            </numIndex>
                            <numIndex index="1" type="array">
                                <showitem>
                                    --palette--;LLL:EXT:lang/Resources/Private/Language/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
                                    --palette--;;filePalette
                                </showitem>
                            </numIndex>
                            <numIndex index="2" type="array">
                                <showitem>
                                    --palette--;LLL:EXT:lang/Resources/Private/Language/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
                                    --palette--;;filePalette
                                </showitem>
                            </numIndex>
                            <numIndex index="3" type="array">
                                <showitem>
                                    --palette--;LLL:EXT:lang/Resources/Private/Language/locallang_tca.xlf:sys_file_reference.audioOverlayPalette;audioOverlayPalette,
                                    --palette--;;filePalette
                                </showitem>
                            </numIndex>
                            <numIndex index="4" type="array">
                                <showitem>
                                    --palette--;LLL:EXT:lang/Resources/Private/Language/locallang_tca.xlf:sys_file_reference.videoOverlayPalette;videoOverlayPalette,
                                    --palette--;;filePalette
                                </showitem>
                            </numIndex>
                            <numIndex index="5" type="array">
                                <showitem>
                                    --palette--;LLL:EXT:lang/Resources/Private/Language/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
                                    --palette--;;filePalette
                                </showitem>
                            </numIndex>
                        </types>
                    </overrideChildTca>
                </config>
            </TCEforms>
        </background_image>

After enable it, you can define custom ratio via TsConfig:

TCEFORM.sys_file_reference.crop.config.cropVariants {
  default {
    title = LLL:EXT:lang/Resources/Private/Language/locallang_wizards.xlf:imwizard.ratio.free
    selectedRatio = NaN
    allowedAspectRatios {
      NaN {
        title = free
        value = 0.0
      }
    }
  }
}

Works on TYPO3 8 LTS



回答2:

Not possible afaik. You will need to set an overall default and adjust it for all other elements using TCA.