diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityType.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityType.php index 9948c74..ef46168 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityType.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityType.php @@ -125,4 +125,11 @@ public function getDataTable() { return FALSE; } + /** + * {@inheritdoc} + */ + public function getConfigDependencyKey() { + return 'config'; + } + } diff --git a/core/lib/Drupal/Core/Entity/ContentEntityType.php b/core/lib/Drupal/Core/Entity/ContentEntityType.php index 213c097..f9de958 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityType.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityType.php @@ -29,4 +29,11 @@ public function getConfigPrefix() { return FALSE; } + /** + * {@inheritdoc} + */ + public function getConfigDependencyKey() { + return 'content'; + } + } diff --git a/core/lib/Drupal/Core/Entity/EntityType.php b/core/lib/Drupal/Core/Entity/EntityType.php index 5ea863d..faf8856 100644 --- a/core/lib/Drupal/Core/Entity/EntityType.php +++ b/core/lib/Drupal/Core/Entity/EntityType.php @@ -680,4 +680,14 @@ public function getListCacheTags() { return $this->list_cache_tags; } + /** + * {@inheritdoc} + */ + public function getConfigDependencyKey() { + // Return 'content' for the default implementation as important distinction + // is that dependencies on other configuration entities are hard + // dependencies and have to exist before creating the dependent entity. + return 'content'; + } + } diff --git a/core/lib/Drupal/Core/Entity/EntityTypeInterface.php b/core/lib/Drupal/Core/Entity/EntityTypeInterface.php index f8237a5..26c913b 100644 --- a/core/lib/Drupal/Core/Entity/EntityTypeInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityTypeInterface.php @@ -638,4 +638,14 @@ public function setUriCallback($callback); * @return string[] */ public function getListCacheTags(); + + /** + * Gets the key that is used to store configuration dependencies. + * + * @return string + * The key to be used in configuration dependencies when storing + * dependencies on entities of this type. + */ + public function getConfigDependencyKey(); + } 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 a6c6bed..87868d6 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php @@ -247,17 +247,15 @@ public function hasNewEntity() { */ public static function calculateDependencies(FieldDefinitionInterface $field_definition) { $dependencies = []; - if (is_array($field_definition->default_value) && count($field_definition->default_value)) { $target_entity_type = \Drupal::entityManager()->getDefinition($field_definition->getFieldStorageDefinition()->getSetting('target_type')); - $key = $target_entity_type instanceof ConfigEntityType ? 'config' : 'content'; foreach ($field_definition->default_value as $default_value) { if (is_array($default_value) && isset($default_value['target_uuid'])) { $entity = \Drupal::entityManager()->loadEntityByUuid($target_entity_type->id(), $default_value['target_uuid']); // If the entity does not exist do not create the dependency. // @see \Drupal\Core\Field\EntityReferenceFieldItemList::processDefaultValue() if ($entity) { - $dependencies[$key][] = $entity->getConfigDependencyName(); + $dependencies[$target_entity_type->getConfigDependencyKey()][] = $entity->getConfigDependencyName(); } } }