W3cubDocs

/Drupal 8

public function EntityDisplayBase::calculateDependencies

public EntityDisplayBase::calculateDependencies()

Calculates dependencies and stores them in the dependency property.

Return value

$this

Overrides ConfigEntityBase::calculateDependencies

See also

\Drupal\Core\Config\Entity\ConfigDependencyManager

File

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

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->entityManager()->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 = $this->entityManager()->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->entityManager()->getStorage('entity_' . $this->displayContext . '_mode')->load($target_entity_type->id() . '.' . $this->mode);
    $this->addDependency('config', $mode_entity->getConfigDependencyName());
  }
  return $this;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!EntityDisplayBase.php/function/EntityDisplayBase::calculateDependencies/8.1.x