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 8073b18..b31829c 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php @@ -256,12 +256,11 @@ public static function calculateDependencies(FieldDefinitionInterface $field_def 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(); } - else { - throw new MissingDefaultValueException($target_entity_type->id(), $default_value['target_uuid'], $field_definition->getName()); - } } } } diff --git a/core/modules/entity_reference/src/Exception/MissingDefaultValueException.php b/core/modules/entity_reference/src/Exception/MissingDefaultValueException.php deleted file mode 100644 index 2070e27..0000000 --- a/core/modules/entity_reference/src/Exception/MissingDefaultValueException.php +++ /dev/null @@ -1,33 +0,0 @@ -getEntityTypeId() . ']'] = TRUE; } $this->drupalPostForm($this->entityType . '/structure/' . $this->bundle .'/fields/' . $this->entityType . '.' . $this->bundle . '.' . $this->fieldName, $field_edit, t('Save settings')); - $config_entity = $this->container->get('config.factory')->get('field.field.' . $this->entityType . '.' . $this->bundle . '.' . $this->fieldName)->get(); // Ensure the configuration has the expected dependency on the entity that // is being used a default value. - $this->assertTrue(in_array($referenced_entities[0]->getConfigDependencyName(), $config_entity['dependencies'][$key]), String::format('Expected @type dependency @name found', ['@type' => $key, '@name' => $referenced_entities[0]->getConfigDependencyName()])); + $field = FieldConfig::loadByName($this->entityType, $this->bundle, $this->fieldName); + $this->assertTrue(in_array($referenced_entities[0]->getConfigDependencyName(), $field->getDependencies()[$key]), String::format('Expected @type dependency @name found', ['@type' => $key, '@name' => $referenced_entities[0]->getConfigDependencyName()])); // Ensure that the field can be imported without change even after the // default value deleted. $referenced_entities[0]->delete(); - $this->assertConfigEntityImport(FieldConfig::loadByName($this->entityType, $this->bundle, $this->fieldName)); - - // Test re-saving the field now that the default value does not exist. - $msg = 'Expected MissingDefaultValueException exception thrown.'; - try { - FieldConfig::loadByName($this->entityType, $this->bundle, $this->fieldName)->save(); - $this->fail($msg); - } - catch (MissingDefaultValueException $e) { - $this->pass($msg); - $this->assertEqual($e->getMessage(), sprintf("Default value '%s' of entity type '%s' for '%s' field was not found.", $referenced_entities[0]->uuid(), $referenced_entities[0]->getEntityTypeId(), $this->fieldName)); - } + $this->assertConfigEntityImport($field); + + // Once the default value has been removed after saving the dependency + // should be removed. + $field = FieldConfig::loadByName($this->entityType, $this->bundle, $this->fieldName); + $field->save(); + $dependencies = $field->getDependencies(); + $this->assertFalse(isset($dependencies[$key]) && in_array($referenced_entities[0]->getConfigDependencyName(), $dependencies[$key]), String::format('@type dependency @name does not exist.', ['@type' => $key, '@name' => $referenced_entities[0]->getConfigDependencyName()])); } }