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.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

froboy created an issue. See original summary.

froboy’s picture

Status: Active » Needs review
erikaagp’s picture

Status: Needs review » Reviewed & tested by the community

the way how setCardinality was implemented, works for me.

froboy’s picture

Status: Reviewed & tested by the community » Needs review

@erikaagp thanks for your time! As this is a small but nontrivial change, could you please provide more detailed feedback or testing steps you used?

Thanks again, and welcome!

owenbush’s picture

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?

owenbush’s picture

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.

plopesc’s picture

Version: 2.0.x-dev » 3.x-dev

Moving to 3.x

  • plopesc committed 436f42da on 3.x
    Issue #3316144 by plopesc, froboy, owenbush, erikaagp: Field cardinality...
plopesc’s picture

Status: Needs review » Fixed

MR merged!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.