You are here

public function Entity::calculateDependencies in Entity Embed 8

Calculates dependencies for the configured plugin.

Dependencies are saved in the plugin's configuration entity and are used to determine configuration synchronization order. For example, if the plugin integrates with specific user roles, this method should return an array of dependencies listing the specified roles.

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 EmbedTypeBase::calculateDependencies

See also

\Drupal\Core\Config\Entity\ConfigDependencyManager

\Drupal\Core\Entity\EntityInterface::getConfigDependencyName()

File

src/Plugin/EmbedType/Entity.php, line 282

Class

Entity
Entity embed type.

Namespace

Drupal\entity_embed\Plugin\EmbedType

Code

public function calculateDependencies() {
  $this
    ->addDependencies(parent::calculateDependencies());
  $entity_type_id = $this
    ->getConfigurationValue('entity_type');
  $entity_type = $this->entityTypeManager
    ->getDefinition($entity_type_id);
  $this
    ->addDependency('module', $entity_type
    ->getProvider());

  // Calculate bundle dependencies.
  foreach ($this
    ->getConfigurationValue('bundles') as $bundle) {
    $bundle_dependency = $entity_type
      ->getBundleConfigDependency($bundle);
    $this
      ->addDependency($bundle_dependency['type'], $bundle_dependency['name']);
  }

  // Calculate display Entity Embed Display dependencies.
  foreach ($this
    ->getConfigurationValue('display_plugins') as $display_plugin) {
    $instance = $this->displayPluginManager
      ->createInstance($display_plugin);
    $this
      ->calculatePluginDependencies($instance);
  }
  $entity_browser = $this
    ->getConfigurationValue('entity_browser');
  if ($entity_browser && $this->entityTypeManager
    ->hasDefinition('entity_browser')) {
    $browser = $this->entityTypeManager
      ->getStorage('entity_browser')
      ->load($entity_browser);
    if ($browser) {
      $this
        ->addDependency($browser
        ->getConfigDependencyKey(), $browser
        ->getConfigDependencyName());
    }
  }
  return $this->dependencies;
}