typo3 - 从sitepackage扩展cropVariants

问题描述 投票:0回答:1

Typo3 v12 与 Fluid_styled_content。

我想定义一个自定义的cropVariant而不覆盖默认的cropVariant。 我想要这样做的原因是使用

<f:image>
视图助手来加载图像的最佳尺寸的方形预览。

我认为这会起作用:

local_packages/mysitepackage/Configuration/TCA/Overrides/sys_file_reference.php

<?php
defined('TYPO3') or die('Access denied.');

call_user_func(function() {
    $GLOBALS['TCA']['sys_file_reference']['columns']['crop']['config']['cropVariants']['square'] = [
        'title' => 'square',
        'allowedAspectRatios' => [
            '1:1' => [
                'title' => '1:1',
                'value' => 1.0
            ],
        ],
        'selectedRatio' => '1:1',
        'cropArea' => [
            'x' => 0.0,
            'y' => 0.0,
            'width' => 1.0,
            'height' => 1.0,
        ],
    ];
});

--> 但遗憾的是这会覆盖默认的cropVariant。

附加信息:

  • 我尝试将其与预先存在的
    ['TCA']['sys_file_reference']['columns']['crop']['config']['cropVariants']
    合并,但在调用我的 TCA 覆盖函数时它尚未定义。
  • 我设法将 原始默认cropVariant硬编码到我的文件中以保留它,但显然我宁愿扩展cropVariants
    dynamically
    以供将来验证。
  • 链接的源代码提到了cropVariantcollections,但我在文档中找不到有关该信息的信息...

非常感谢任何帮助或提示。

typo3 fluid-styled-content
1个回答
0
投票

简短回答

不,如果定义了

sys_file_reference
级别的自定义裁剪变体,则无法保留默认值。请参阅下面的长答案和变体
1. generic on sys_file_reference level

这意味着,您需要手动定义它或在 contentElement / 字段级别定义cropVariants(另请参阅下面的长答案)。

长答案 - 简介

定义cropVariants基本上有两种方法:

  1. sys_file_reference
    级别通用
  2. 作为特定内容元素的覆盖

1。

sys_file_reference
级别通用

您提供的代码基本上是为所有文件引用定义cropVariants globally的方式。

记录在这里:

重点是,一旦某些扩展在该级别定义了cropVariants,

default
cropVariant就会被删除。以下代码负责此操作:

// see: https://github.com/TYPO3/typo3/blob/db1408d90d8b62df2b86116af55163ffcab9362b/typo3/sysext/backend/Classes/Form/Element/ImageManipulationElement.php#L228-L231

// If ratios are set do not add default options
if (isset($baseConfiguration['cropVariants'])) {
    unset($defaultConfig['cropVariants']);
}

那是有意为之。这意味着,您需要另外设置自己的“默认值”,从此处将其复制并粘贴为覆盖文件中的默认变体: https://github.com/TYPO3/typo3/blob/db1408d90d8b62df2b86116af55163ffcab9362b/typo3/sysext/backend/Classes/Form/Element/ImageManipulationElement.php#L48-L85

一个简单的示例,没有来自其他扩展和覆盖的预先存在的检查:

$GLOBALS['TCA']['sys_file_reference']['columns']['crop'] = [
  'config' => [
    'cropVariants' => [
        'default' => [
            'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_wizards.xlf:imwizard.crop_variant.default',
            'allowedAspectRatios' => [
                '16:9' => [
                    'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_wizards.xlf:imwizard.ratio.16_9',
                    'value' => 16 / 9,
                ],
                '3:2' => [
                    'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_wizards.xlf:imwizard.ratio.3_2',
                    'value' => 3 / 2,
                ],
                '4:3' => [
                    'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_wizards.xlf:imwizard.ratio.4_3',
                    'value' => 4 / 3,
                ],
                '1:1' => [
                    'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_wizards.xlf:imwizard.ratio.1_1',
                    'value' => 1.0,
                ],
                'NaN' => [
                    'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_wizards.xlf:imwizard.ratio.free',
                    'value' => 0.0,
                ],
            ],
            'selectedRatio' => 'NaN',
            'cropArea' => [
                'x' => 0.0,
                'y' => 0.0,
                'width' => 1.0,
                'height' => 1.0,
            ],
        ], // default
        'square' => [
            'title' => 'square',
            'allowedAspectRatios' => [
                '1:1' => [
                    'title' => '1:1',
                    'value' => 1.0
                ],
            ],
            'selectedRatio' => '1:1',
            'cropArea' => [
                'x' => 0.0,
                'y' => 0.0,
                'width' => 1.0,
                'height' => 1.0,
            ],
        ], // square
    ], // cropVariants
  ], // config
];

2。作为特定内容元素的覆盖

如果您想在每个 contentElement 或字段级别覆盖或设置cropVariants,请参阅该变体的文档链接: https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/CropVariants/ContentElement/Index.html

在这里,如果没有删除,则不需要重新定义“默认”变体。但您可以根据内容元素“附加/更改”它或禁用某些事件。

这里需要的功能称为

overrideChildTca
。这里是从
textmexia
内容元素和
assets
字段的文档中获取的示例 - 只是使用您的 CropVariant 而不是文档中的示例:

$GLOBALS['TCA']['tt_content']['types']['textmedia']['columnsOverrides']['assets']['config']['overrideChildTca']['columns']['crop']['config'] = [
    'cropVariants' => [
       'default' => [
           'disabled' => true,
       ],
       'square' => [
            'title' => 'square',
            'allowedAspectRatios' => [
                '1:1' => [
                    'title' => '1:1',
                    'value' => 1.0
                ],
            ],
            'selectedRatio' => '1:1',
            'cropArea' => [
                'x' => 0.0,
                'y' => 0.0,
                'width' => 1.0,
                'height' => 1.0,
            ],
       ],
    ],
];
© www.soinside.com 2019 - 2024. All rights reserved.