Entity reference conditionals store null values

Created on 9 September 2022, almost 2 years ago
Updated 1 September 2023, 10 months ago

Problem/Motivation

Entity reference conditionals are broken by the storing of null values. The edit form for conditionals shows the following warning:

Warning: array_flip(): Can only flip STRING and INTEGER values! in Drupal\Core\Entity\EntityStorageBase->loadMultiple() (line 261 of core/lib/Drupal/Core/Entity/EntityStorageBase.php)

The culprit is is L40 of Drupal\conditional_fields\Plugin\conditional_fields\handler\EntityReference which loads empty values. However, simply using array_filter to get rid of them at that stage only masks the real problem.

When using select lists, the "null" value makes it into the visibility check and so the fields are never made visible,

Steps to reproduce

Add a conditional from any field to an entity reference (i.e taxonomy) field and select any value from the taxonomy. Returning to the edit form will show a warning. Attempting to make the field visible on the entity form by selecting the value from the a dropdown does not show the field.

Proposed resolution

Unset any invalid target_id values from the ConditionalFieldEditForm submit handler.

🐛 Bug report
Status

Needs review

Version

4.0

Component

Code

Created by

🇳🇿New Zealand dieuwe Auckland, NZ

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.

Production build 0.69.0 2024