You are here

public function EntityDisplayBase::calculateDependencies in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Entity/EntityDisplayBase.php \Drupal\Core\Entity\EntityDisplayBase::calculateDependencies()

Calculates dependencies and stores them in the dependency property.

Return value

$this

Overrides ConfigEntityBase::calculateDependencies

See also

\Drupal\Core\Config\Entity\ConfigDependencyManager

1 call to EntityDisplayBase::calculateDependencies()
LayoutBuilderEntityViewDisplay::calculateDependencies in core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php
Calculates dependencies and stores them in the dependency property.
1 method overrides EntityDisplayBase::calculateDependencies()
LayoutBuilderEntityViewDisplay::calculateDependencies in core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php
Calculates dependencies and stores them in the dependency property.

File

core/lib/Drupal/Core/Entity/EntityDisplayBase.php, line 301

Class

EntityDisplayBase
Provides a common base class for entity view and form displays.

Namespace

Drupal\Core\Entity

Code

public function calculateDependencies() {
  parent::calculateDependencies();
  $target_entity_type = $this
    ->entityTypeManager()
    ->getDefinition($this->targetEntityType);

  // Create dependency on the bundle.
  $bundle_config_dependency = $target_entity_type
    ->getBundleConfigDependency($this->bundle);
  $this
    ->addDependency($bundle_config_dependency['type'], $bundle_config_dependency['name']);

  // If field.module is enabled, add dependencies on 'field_config' entities
  // for both displayed and hidden fields. We intentionally leave out base
  // field overrides, since the field still exists without them.
  if (\Drupal::moduleHandler()
    ->moduleExists('field')) {
    $components = $this->content + $this->hidden;
    $field_definitions = \Drupal::service('entity_field.manager')
      ->getFieldDefinitions($this->targetEntityType, $this->bundle);
    foreach (array_intersect_key($field_definitions, $components) as $field_name => $field_definition) {
      if ($field_definition instanceof ConfigEntityInterface && $field_definition
        ->getEntityTypeId() == 'field_config') {
        $this
          ->addDependency('config', $field_definition
          ->getConfigDependencyName());
      }
    }
  }

  // Depend on configured modes.
  if ($this->mode != 'default') {
    $mode_entity = $this
      ->entityTypeManager()
      ->getStorage('entity_' . $this->displayContext . '_mode')
      ->load($target_entity_type
      ->id() . '.' . $this->mode);
    $this
      ->addDependency('config', $mode_entity
      ->getConfigDependencyName());
  }
  return $this;
}