Field cardinality is not preserved on inheritance

Created on 18 October 2022, about 2 years ago
Updated 27 January 2023, almost 2 years ago

Problem/Motivation

When working with an multi-valued entity reference field, I noticed that only the first value was inherited. I believe the FieldStorageDefinition is missing setCardinality as per this blog post.

Steps to reproduce

- Configure a multivalued field inheritance (in my case a taxonomy term on a recurring event)
- Add multiple values to the field
- Observe only the first value is passed to the destination field.

Proposed resolution

Add setCardinality.

πŸ› Bug report
Status

Needs review

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States froboy Chicago, IL

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States owenbush Denver, CO

    This change looks good and makes sense to me.

    One thing I wonder is for inherited fields that append or prepend, this may be problematic. If the cardinality of the source field is 3, for example, and we set the cardinality of the inherited field to 3, then what happens with values appended/prepended?

    There are a couple of approaches we could take:

    1. Always just make them unlimited, to handle any combination of source+destination field cardinalities
    2. Set to unlimited if source field or destination field are unlimited, otherwise source field cardinality + destination field cardinality

    Given that this has probably arisen from a use-case of yours, what approach do you think makes most sense to handle the possibility of appending/prepending values from the destination entity too?

  • πŸ‡ΊπŸ‡ΈUnited States owenbush Denver, CO

    I've gone ahead and made some changes to better determine what the cardinality should be.

    Inherited fields will just use the source field cardinality

    Fallback fields will use the larger of the source field and destination field cardinalities, unless one of them is unlimited, in which case it will be unlimited.

    Appended/Prepended fields will use the source cardinality + the destination field cardinality - unless one of them is unlimited, in which case it will be unlimited.

Production build 0.71.5 2024