public static function EntityReferenceItem::calculateDependencies in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::calculateDependencies()
Calculates dependencies for field items.
Dependencies are saved in the field configuration entity and are used to determine configuration synchronization order. For example, if the field type's default value is a content entity, this method should return an array of dependencies listing the content entities.
Parameters
\Drupal\Core\Field\FieldDefinitionInterface $field_definition: The field definition.
Return value
array An array of dependencies grouped by type (config, content, module, theme). For example:
array(
'config' => array(
'user.role.anonymous',
'user.role.authenticated',
),
'content' => array(
'node:article:f0a189e6-55fb-47fb-8005-5bef81c44d6d',
),
'module' => array(
'node',
'user',
),
'theme' => array(
'seven',
),
);
Overrides FieldItemBase::calculateDependencies
See also
\Drupal\Core\Config\Entity\ConfigDependencyManager
\Drupal\Core\Config\Entity\ConfigEntityInterface::getConfigDependencyName()
File
- core/
lib/ Drupal/ Core/ Field/ Plugin/ Field/ FieldType/ EntityReferenceItem.php, line 397 - Contains \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem.
Class
- EntityReferenceItem
- Defines the 'entity_reference' entity field type.
Namespace
Drupal\Core\Field\Plugin\Field\FieldTypeCode
public static function calculateDependencies(FieldDefinitionInterface $field_definition) {
$dependencies = parent::calculateDependencies($field_definition);
$manager = \Drupal::entityManager();
$target_entity_type = $manager
->getDefinition($field_definition
->getFieldStorageDefinition()
->getSetting('target_type'));
// Depend on default values entity types configurations.
if ($default_value = $field_definition
->getDefaultValueLiteral()) {
foreach ($default_value as $value) {
if (is_array($value) && isset($value['target_uuid'])) {
$entity = \Drupal::entityManager()
->loadEntityByUuid($target_entity_type
->id(), $value['target_uuid']);
// If the entity does not exist do not create the dependency.
// @see \Drupal\Core\Field\EntityReferenceFieldItemList::processDefaultValue()
if ($entity) {
$dependencies[$target_entity_type
->getConfigDependencyKey()][] = $entity
->getConfigDependencyName();
}
}
}
}
// Depend on target bundle configurations.
$handler = $field_definition
->getSetting('handler_settings');
if (!empty($handler['target_bundles'])) {
if ($bundle_entity_type_id = $target_entity_type
->getBundleEntityType()) {
if ($storage = $manager
->getStorage($bundle_entity_type_id)) {
foreach ($storage
->loadMultiple($handler['target_bundles']) as $bundle) {
$dependencies[$bundle
->getConfigDependencyKey()][] = $bundle
->getConfigDependencyName();
}
}
}
}
return $dependencies;
}