Problem/Motivation

Steps to reproduce

  1. Drupal 11.4.x on PHP 8.x.
  2. Install Commerce + Commerce Shipping 3.x; enable shipping on an order type.
  3. Create an order and add a shipment to it.
  4. Load the order via the entity API (or view the cart block / order admin).
  5. Observe the two Undefined array key warnings, and that $order->get('shipments')->first()->target_id is NULL.

Minimal, non-Commerce: define a BundleFieldDefinition entity-reference field with cardinality > 1 (dedicated-table storage) on any content entity, save a value, then load the entity.

Proposed resolution

Build $field_columns from the field's own storage definition (already in scope in the loop), as the code did before #3594426. This is identical to getColumnNames() for base/config fields, and correctly populated for bundle fields:

$field_columns[$field_name] = [];
foreach (array_keys($storage_definition->getColumns()) as $property_name) {
  $field_columns[$field_name][$property_name] = $this->tableMapping->getFieldColumnName($storage_definition, $property_name);
}

Patch attached; verified on a production-bound Commerce site (shipments load with real target_ids, warnings gone).

Remaining tasks

  • Confirm the approach (vs. teaching getColumnNames() to fall back to the passed storage definition).
  • Add test coverage: load an entity with a dedicated-table BundleFieldDefinition field (single- and multi-cardinality) and assert values load without warnings.
  • Reviews / MR against 11.4.x and 11.x.

User interface changes

None.

Introduced terminology

None.

API changes

None. Restores the pre-11.4.0 behavior of loadFromDedicatedTables(); no public method signatures change.

Data model changes

None.

Release notes snippet

Fixed a regression from 11.4.0 where loading a content entity that has a bundle field (BundleFieldDefinition) stored in a dedicated table populated that field with empty/NULL values and triggered "Undefined array key" warnings. Notably, this restores loading of Commerce Shipping's order shipments field.

Comments

age3141592 created an issue. See original summary.

liam morland’s picture

Issue tags: -`regression`, -`PHP 8`, -`Entity Field API` +Regression, +PHP 8.0, +Entity Field API
liam morland’s picture

Issue tags: -PHP 8.0

Drupal 11 only works on PHP 8 anyway.

quietone’s picture

Version: 11.4.x-dev » main
Issue summary: View changes
Issue tags: -Regression, -Entity Field API +Needs title update

Hi, Issues for Drupal core should be targeted to the 'main' branch, our primary development branch. Changes are made on the main branch first, and are then back ported as needed according to the Core change policies. The version the problem was discovered on should be stated in the issue summary Problem/Motivation section. Thanks.

Tagging for a title update because the title should be a description of what is being fixed or improved. The title is used as the git commit message so it should be meaningful and concise. See List of issue fields.