diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php index bd164a9..7aaf80d 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php @@ -350,6 +350,19 @@ public static function onDependencyRemoval(FieldDefinitionInterface $field_defin if (isset($dependencies[$bundle->getConfigDependencyKey()][$bundle->getConfigDependencyName()])) { unset($handler_settings['target_bundles'][$bundle->id()]); $bundles_changed = TRUE; + + // In case we deleted the only target bundle allowed by the field we + // have to log a warning message because the field will not function + // correctly anymore. + if ($handler_settings['target_bundles'] === []) { + \Drupal::logger('entity_reference')->critical('The %target_bundle bundle (entity type: %target_entity_type) was deleted. As a result, the %field_name entity reference field (entity_type: %entity_type, bundle: %bundle) no longer has any valid bundle it can reference. The field is not working correctly anymore and has to be adjusted.', [ + '%target_bundle' => $bundle->label(), + '%target_entity_type' => $bundle->getEntityType()->getBundleOf(), + '%field_name' => $field_definition->getName(), + '%entity_type' => $field_definition->getTargetEntityTypeId(), + '%bundle' => $field_definition->getTargetBundle() + ]); + } } } } diff --git a/core/modules/entity_reference/entity_reference.module b/core/modules/entity_reference/entity_reference.module index d24bac3..cd9e1d7 100644 --- a/core/modules/entity_reference/entity_reference.module +++ b/core/modules/entity_reference/entity_reference.module @@ -242,6 +242,11 @@ function entity_reference_entity_bundle_rename($entity_type_id, $bundle_old, $bu /** * Implements hook_entity_bundle_delete(). + * + * We are duplicating the work done by + * \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::onDependencyRemoval() + * because we need to take into account bundles that are not provided by a + * config entity type so they are not part of the config dependencies. */ function entity_reference_entity_bundle_delete($entity_type_id, $bundle) { // Gather a list of all entity reference fields.