Issue give WSOD and half of issue in in core before it connect down in line to proper place
Message:
Message TypeError: array_rand(): Argument #1 ($array) must be of type array, bool given w array_rand() (line 357 in .../public_html/web/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php)
Description:
There is somehow possible to send empty $entity_type->getKey('bundle')
which broke next call.
Solution is to patch this function with provided code: .../public_html/web/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php
:
protected static function getRandomBundle(EntityTypeInterface $entity_type, array $selection_settings) {
if ($entity_type->getKey('bundle')) {
$bundle_ids = \Drupal::service('entity_type.bundle.info')->getBundleInfo($entity_type->id());
if (!empty($selection_settings['target_bundles'])) {
$bundle_ids = $selection_settings['target_bundles'];
}
if(!empty($bundle_ids)){
$bundle_ids = array_rand($bundle_ids);
return $bundle_ids;
}
}
}
Note:
I change order so when there is something it always return and I don't return anything if there isn't provided data to align with expectation before patch
Releated issue is what cause in first place to test it.
In my example I don't have any attribute fields. Creating placeholder one (example attribute with one value and not used anywhere) fix issue from commerce perspective.
Need only review, test and apply as patch :)