Closed (fixed)
Project:
Computed Field
Version:
4.0.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
27 Mar 2023 at 17:58 UTC
Updated:
28 May 2024 at 07:20 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
giuseppe87 commentedAttached the patch setting up the cardinality. I hope it's okay, I'm not really expert with plugins.
Ideally, I suppose
SingleValueTraitshould override the default value for the annotation$cardinality, but I have no idea if that is possible and how do that, and I couldn't find an example on internet or other traits to do so.I'd appreciate if someone could explain that (if it's actually possible) or fix the patch. Thanks
Comment #3
giuseppe87 commentedI didn't see that the field may be attached also inside
hook_entity_bundle_field_info_alterfor the "bundle" fields.The patch add the cardinality check also in that hook.
Comment #4
joachim commentedAh yes, I hadn't thought of that! Fields by default are single-valued, but the rendering system is lazy and just iterates anyway.
same.
We don't need this check - just pass on the cardinality, whatever it is.
I'm not sure we should default to unlimited, as BaseFieldDefinition defaults to 1. We should be consistent.
You don't need the default here. It will come from the annotation property's default value if not specified in the plugin annotation.
It's simpler to just say != 1 here I think?
Missing full stop.
Comment #5
_pratik_Changes regarding #4, not sure on point 3.
Thanks
Comment #6
giuseppe87 commented3. I chose the unlimited instead of 1 because the module "default plugin logic" is a unlimited value field.
The "single" value needs to specify
SingleValueTrait. But this is a mine arbitrary idea, it seems sensible to choose "1" as default.5. I actually initially wrote something like that, but after I copied what
BaseFieldDefinition::isMultiple()does:But I've no idea if this is some overkill code or there's some obscure valid reason behind it.
Comment #7
roxflame commentedNot sure if this is related, but I get errors importing nodes in feeds if they would return multiple values when calculated.
"Keywords (computed_keywords): Keywords: this field cannot hold more than 1 values."
This field does hold more than one value just fine, and displays as multiple throughout the site, but, it breaks my feeds from importing...
Comment #9
karlshea@roxflame I think cardinality was supposed to go in your plugin's
getFieldCardinality(), not ingetFieldDefinitionSettingsComment #11
karlsheaComment #12
colanCould this be related to #3437020: Allow computed function callbacks to determine cardinality dynamically?
Comment #13
joachim commented> 3. I chose the unlimited instead of 1 because the module "default plugin logic" is a unlimited value field.
> The "single" value needs to specify SingleValueTrait. But this is a mine arbitrary idea, it seems sensible to choose "1" as default.
The plugin logic was a mistake on my part -- I hadn't checked what base fields and config fields do.
We're still in alpha releases, so it's fine to change our API.
> Could this be related to #3437020: Allow computed function callbacks to determine cardinality dynamically?
Yes, they seem similar. Though I don't really understand the patch over there. Let's get this one in first.
Comment #14
joachim commentedMade a few changes, added a test.
Committed the MR.
Comment #17
giuseppe87 commentedHi, may suggest that the changelog of alpha9 explain that this MR introduced a breaking change, changing the default cardinality of the plugin from unlimited to single?
I don't know if there are others can be affected too, and if this can happen also with the rendering system, but when I switched from alpha8 + patch to alpha9 I got problems due this MR - namely, via JSON:API empty fields returned "false" instead of an empty array.
Considering I was puzzled a bit before finding the cause, and I'm the one opening the issue, others could be have even more difficulties to find the problem.