Problem/Motivation
Steps to reproduce
- Drupal 11.4.x on PHP 8.x.
- Install Commerce + Commerce Shipping 3.x; enable shipping on an order type.
- Create an order and add a shipment to it.
- Load the order via the entity API (or view the cart block / order admin).
- Observe the two
Undefined array keywarnings, and that$order->get('shipments')->first()->target_idisNULL.
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
BundleFieldDefinitionfield (single- and multi-cardinality) and assert values load without warnings. - Reviews / MR against
11.4.xand11.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.
| Comment | File | Size | Author |
|---|---|---|---|
| core-loadFromDedicatedTables-bundle-field-columns.patch | 1.16 KB | age3141592 |
Comments
Comment #2
liam morlandComment #3
liam morlandDrupal 11 only works on PHP 8 anyway.
Comment #4
quietone commentedHi, 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.