Problem/Motivation
ContentEntityStorageInterface defines the 'createWithSampleValues' method, to help tools like layout builder provide sample values while a layout (or anything else using Context) is configured. When this is called to generate an order, it eventually calls
EntityReferenceItem::generateSampleValue() which uses EntityReferenceItem::getRandomBundle() to ascertain which bundle of entity to create. getRandomBundle() returns a random key from $selection_settings['target_bundles'] - it expects target bundles to be of the form
[
'bundle1' => 'bundle1',
'bundle2' => 'bundle2',
] - the billing profile field is not defined like this. This causes EntityReferenceItem::generateSampleValue() to make a profile entity with bundle '0' and you get an error.
Steps to reproduce
- Install commerce and commerce_order
- Run
\Drupal::entityTypeManager()->getStorage('commerce_order')->createWithSampleValues('default'); - Get the error
Proposed resolution
Update Order::baseFieldDefinitions() to correctly set the target_bundles in the way EntityReferenceItem expects.
->setSetting('handler_settings', ['target_bundles' => ['customer' => 'customer']])
Remaining tasks
User interface changes
None
API changes
None
Data model changes
None
Issue fork commerce-3170998
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
Comment #2
rlmumfordComment #4
rlmumfordComment #5
rlmumfordDuplicate of #3137225