You are here

public static function DynamicEntityReferenceItem::calculateStorageDependencies in Dynamic Entity Reference 8.2

Same name and namespace in other branches
  1. 8 src/Plugin/Field/FieldType/DynamicEntityReferenceItem.php \Drupal\dynamic_entity_reference\Plugin\Field\FieldType\DynamicEntityReferenceItem::calculateStorageDependencies()

Calculates dependencies for field items on the storage level.

Dependencies are saved in the field storage configuration entity and are used to determine configuration synchronization order. For example, if the field type storage depends on a particular entity type, this method should return an array of dependencies listing the module that provides the entity type.

Dependencies returned from this method are stored in field storage configuration and are always considered hard dependencies. If the dependency is removed the field storage configuration must be deleted.

Parameters

\Drupal\Core\Field\FieldStorageDefinitionInterface $field_storage_definition: The field storage definition.

Return value

array An array of dependencies grouped by type (config, content, module, theme). For example:

[
  'config' => [
    'user.role.anonymous',
    'user.role.authenticated',
  ],
  'content' => [
    'node:article:f0a189e6-55fb-47fb-8005-5bef81c44d6d',
  ],
  'module' => [
    'node',
    'user',
  ],
  'theme' => [
    'seven',
  ],
];

Overrides EntityReferenceItem::calculateStorageDependencies

See also

\Drupal\Core\Config\Entity\ConfigDependencyManager

\Drupal\Core\Config\Entity\ConfigEntityInterface::getConfigDependencyName()

File

src/Plugin/Field/FieldType/DynamicEntityReferenceItem.php, line 718

Class

DynamicEntityReferenceItem
Defines the 'dynamic_entity_reference' entity field type.

Namespace

Drupal\dynamic_entity_reference\Plugin\Field\FieldType

Code

public static function calculateStorageDependencies(FieldStorageDefinitionInterface $field_definition) {
  $dependencies = FieldItemBase::calculateStorageDependencies($field_definition);
  $entity_manager = \Drupal::entityTypeManager();
  foreach (static::getTargetTypes($field_definition
    ->getSettings()) as $entity_type_id) {
    if ($entity_manager
      ->hasDefinition($entity_type_id) && ($target_entity_type = $entity_manager
      ->getDefinition($entity_type_id))) {
      $dependencies['module'][] = $target_entity_type
        ->getProvider();
    }
  }
  return $dependencies;
}