Fix bundle logic to select fields correctly

Created on 7 May 2020, over 4 years ago
Updated 3 July 2024, 3 months ago

I found that using the ContentEntity d8_entity plugin for nodes with a particular bundle specified in the migration config would result in *all* fields being considered, due to a bug in the logic that tries to filter out fields for the desired bundle:

if ($bundle && $data['bundle'] === $bundle) {
  $fields[$data['field_name']] = $data
}
else {
  $fields[$data['field_name']] = $data
}

This logic ends up selecting ALL fields, because the first condition succeeds when $data['bundle'] matches $bundle, but the else condition happens even if $bundle is set and there's no match.

This simple patch breaks up the initial test, like so:

if ($bundle) {
  # Bundle configured, check if this field matches it, and if so select the field.
  if ($data['bundle'] === $bundle)

}
else {
  # Pick all fields, since no bundle is configured
}
🐛 Bug report
Status

Closed: duplicate

Component

Code

Created by

🇨🇦Canada spiderman Halifax, NS

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.71.5 2024