Skip to content
Snippets Groups Projects
Commit 9eb4efb9 authored by Angie Byron's avatar Angie Byron
Browse files

Issue #2390615 by alexpott: Add method to determine config dependency key depending on entity type

parent 7c6a23fe
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -125,4 +125,11 @@ public function getDataTable() {
return FALSE;
}
/**
* {@inheritdoc}
*/
public function getConfigDependencyKey() {
return 'config';
}
}
......@@ -29,4 +29,11 @@ public function getConfigPrefix() {
return FALSE;
}
/**
* {@inheritdoc}
*/
public function getConfigDependencyKey() {
return 'content';
}
}
......@@ -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';
}
}
......@@ -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();
}
......@@ -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();
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment