overrideChildTca does not work as expected for cropVariants (and maybe in other cases aswell)
$GLOBALS['TCA']['sys_file_reference']['columns']['crop']['config']['cropVariants'] = [ 'default' => [ 'title' => 'default', 'selectedRatio' => 'NaN', 'allowedAspectRatios' => [ 'NaN' => [ 'title' => 'Free', 'value' => 0.0 ] ] ], 'other' => [ 'title' => 'other', 'selectedRatio' => 'NaN', 'allowedAspectRatios' => [ 'NaN' => [ 'title' => 'Free', 'value' => 0.0 ] ] ] ];
$GLOBALS['TCA']['pages']['columns']['media']['config']['overrideChildTca']['columns']['crop']['config']['cropVariants'] = [ 'default' => [ 'title' => 'title for this field', 'selectedRatio' => '16:9', 'allowedAspectRatios' => [ 'NaN' => [ 'title' => 'Free', 'value' => 0.0 ], '16:9' => [ 'title' => '16:9', 'value' => 1.7777777 ] ] ] ];
Expected behaviour: The field "media" of "pages" has only one crop variant named "title for this field" with 2 aspect ratios "Free" and "16:9".
Actual behaviour: The field "media" of "pages" still has 2 crop variants ("title for this field" and "other") and the ascept ratios also get merged instead of overwritten ("default" has "NaN" and "16:9" while "other" has "NaN")
"overrideChildTca" thus in this case (and maybe others) only merges the arrays instead of replacing them. Merging is not what an option with "override" in the name should do.
This makes it impossible to have fewer crop variants and aspect ratios in a specific field than defined in the field of sys_file_reference.
#2 Updated by Beat Haenger 7 months ago
Okay, so for removing crop variants you can use
$GLOBALS['TCA']['pages']['columns']['media']['config']['overrideChildTca']['columns']['crop']['config']['cropVariants'] = [ 'name-of-crop-variant' => [ 'disabled' => true, ] ];
But for removing aspect ratios for a crop variant in a specific field this does not work. And still the above solution is not logical and not well documented. This is still a bug.
#3 Updated by Josef Glatz 7 months ago
- Status changed from New to Needs Feedback
I also had difficulties at the beginning when working with all the possibilities according the cropVariants and it's configuration.
In general, all the documentation about it can be found in the ChangeLog RsT files in
ext:core/Documentation/**/*. They get rendered on https://docs.typo3.org. I assume you have already read the relevant information
Let's have also a look if my personal documentation (my personal cheatsheet) can explain it to you from a different perspective: (just concentrate on the TYPO3 Core only explanation)
Primary usage scenarios are:¶
- Case 1) Set a global/default cropVariants configuration (which is used if you do not make a more specific configuration)
- Case 2) Set a cropVariants configuration for a specific field of a specific table (where you optionally can disable the default/global cropVariants configuration)
- Case 3) Set a cropVariants configuration for a specific field of a specific type of a table (where you optionally can disable the default/global cropVariants configuration)
Examples (from my personal documentation):¶
- Case 1) Global/Default cropVariants configuration for TYPO3 instance
- Case 2) Custom cropVariants configuration for a specific field of a specific table
- Case 3) (unfortunately, I have no example in my personal documentation. but basically you have to add your cropVariants config (hereinafter referred to as $config) part like
$GLOBALS['TCA']['tt_content']['types']['textpic']['columnsOverrides']['image']['config']['overrideChildTca']['columns']['crop']['config']['cropVariants'] = $config;)
For me, the mentioned documentation within the core (the RsT's) is consistent. And yes, if you define crop variants in TCA/Overrides for sys_file_reference, then these are the defaults which you must disable if you don't want them.
I ask you to go through my examples and the mentioned RsT's and give feedback again please!
#4 Updated by Beat Haenger 7 months ago
Yes, disabling "global" crop variants for a field works. (Global means defined in the crop field of sys_file_reference.) Adding crop variants for a field always worked. My issue with this is, that the option "overrideChildTca" is not really an override because if it was you would not have to use "disabled" for global crop variants. Instead the defninition of variants for a field should replace the global variants. Here a core person should make a statement. Maybe "overrideChildTca" works generally as a merging instead of a replacement (then it should be renamed in my opinion).
The second part of the issue is that the option to disable global crop variants for a field cannot also be used to disable aspect ratios of an existing crop variant for a specific field. This means for example that if the global crop variant "lg" has the aspect ratios "16:9", "1:1" and "4:3" it is not possible to have the same crop variant "lg" in a field with only the aspect ratio "16:9" for example. Here the "disabled" option seems not to be implemented.
This could be solved by implementing "disabled" for aspect ratios the way it is implemented for crop variants. But I actually think that the first part of the bug (replacing vs. merging) should be solved which would automatically solve the second part aswell.
#5 Updated by Josef Glatz 7 months ago
What I understood so far is, that in generally it's better to configure a small/simple default and set it for each type specifically. But I know what you mean now! Actually this was the reason why I implemented my own CropVariantsBuilder on top with which I can have my config in a yaml file and add all necessary cropVariants in my TCA/Overrides files specifically for tables, table types in TCA/Overrides (with code completion).Beside that it looks like your issue describes at least two possible separate issues:
- disable/reconfigure/overwrite aspectRatios in an existing cropVariant
overrideChildTcanaming is somehow misleading