本文介绍了如何将cropVariants添加到TYPO3 flexform中的图像字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以像这样覆盖 TCA 中图像字段的cropVaraints:

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
                                        ],
                                    ],
                                ],
                            ],
                        ],
                    ],
                ],
            ],
        ],
    ],
],

我尝试将其用于 flexform - 但没有任何成功.所以我需要的是这样的(但工作:-))

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>

以前有人这样做过吗?

如果不可能,也许我可以绕过 flexform?我目前有一个带有 Image 字段的 gridelement.

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

[更新]正如@fnagel 指出应该可以覆盖默认值,所以我尝试将以下内容放入我的 Overrides/sys_file_reference.php - 但它没有效果 - 我什至无法在 TCA-Inspector 中找到该默认定义......

[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
        ],
    ],
];

写 ot as 也没有效果...

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?

推荐答案

要允许在 flexform 中操作图像,您必须通过 overrideChildTca 属性启用它.

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

示例 flexform:

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>

启用后,您可以通过TsConfig定义自定义比例:

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
      }
    }
  }
}

适用于 TYPO3 8 LTS

Works on TYPO3 8 LTS

这篇关于如何将cropVariants添加到TYPO3 flexform中的图像字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 19:08