You are here

class CalculateEntityDependenciesEvent in Dependency Calculation 8

The event dispatched to calculate dependencies.

Hierarchy

Expanded class hierarchy of CalculateEntityDependenciesEvent

21 files declare their use of CalculateEntityDependenciesEvent
CalculateDependenciesEventDispatcherTrait.php in tests/src/Kernel/EventSubscriber/DependencyCollector/CalculateDependenciesEventDispatcherTrait.php
ConfigEntityDependencyCollector.php in src/EventSubscriber/DependencyCollector/ConfigEntityDependencyCollector.php
DependencyCalculator.php in src/DependencyCalculator.php
DrupalMediaEmbedCollector.php in src/EventSubscriber/DependencyCollector/DrupalMediaEmbedCollector.php
EmbeddedImagesCollector.php in src/EventSubscriber/DependencyCollector/EmbeddedImagesCollector.php

... See full list

File

src/Event/CalculateEntityDependenciesEvent.php, line 12

Namespace

Drupal\depcalc\Event
View source
class CalculateEntityDependenciesEvent extends Event {

  /**
   * The wrapper of the entity for which we are calculating dependencies.
   *
   * @var \Drupal\depcalc\DependentEntityWrapperInterface
   */
  protected $wrapper;

  /**
   * The dependency stack.
   *
   * @var \Drupal\depcalc\DependencyStack
   */
  protected $stack;

  /**
   * CalculateEntityDependenciesEvent constructor.
   *
   * @param \Drupal\depcalc\DependentEntityWrapperInterface $wrapper
   *   The entity for which we are calculating dependencies.
   * @param \Drupal\depcalc\DependencyStack $stack
   *   The dependency stack.
   */
  public function __construct(DependentEntityWrapperInterface $wrapper, DependencyStack $stack) {
    $this->wrapper = $wrapper;
    $this->stack = $stack;
  }

  /**
   * Get the dependency wrapper of the entity.
   *
   * @return \Drupal\depcalc\DependentEntityWrapperInterface
   *   The wrapper.
   */
  public function getWrapper() {
    return $this->wrapper;
  }

  /**
   * Get the entity for which dependencies are being calculated.
   *
   * @return \Drupal\Core\Entity\EntityInterface
   *   The entity.
   */
  public function getEntity() {
    return $this->wrapper
      ->getEntity();
  }

  /**
   * Get the dependency stack.
   *
   * @return \Drupal\depcalc\DependencyStack
   *   The dependency stack.
   */
  public function getStack() {
    return $this->stack;
  }

  /**
   * Add a dependency to this wrapper.
   *
   * @param \Drupal\depcalc\DependentEntityWrapperInterface $dependency
   *   The dependency to be added.
   */
  public function addDependency(DependentEntityWrapperInterface $dependency) {
    $dependencies = $this
      ->getWrapper()
      ->getDependencies();
    if (!array_key_exists($dependency
      ->getUuid(), $dependencies)) {
      $this
        ->getWrapper()
        ->addDependency($dependency, $this
        ->getStack());
    }
  }

  /**
   * Add a group of dependencies to this wrapper.
   *
   * @param \Drupal\depcalc\DependentEntityWrapperInterface ...$dependencies
   *   The dependencies to add to this wrapper.
   */
  public function setDependencies(DependentEntityWrapperInterface ...$dependencies) {
    foreach ($dependencies as $key => $dependency) {
      $this
        ->addDependency($dependency);
    }
  }

  /**
   * A list of all uuids this entity is dependent on.
   *
   * @return \Drupal\depcalc\DependentEntityWrapperInterface[]
   *   The dependencies.
   */
  public function getDependencies() {
    return $this->stack
      ->getDependenciesByUuid(array_keys($this
      ->getWrapper()
      ->getDependencies()));
  }

  /**
   * A list of modules this entity depends upon.
   *
   * @return string[]
   *   The module dependencies.
   */
  public function getModuleDependencies() {
    return $this
      ->getWrapper()
      ->getModuleDependencies();
  }

  /**
   * A list of module dependencies to add to this wrapper.
   *
   * @param string[] $modules
   *   The list of modules.
   */
  public function setModuleDependencies(array $modules) {
    $this
      ->getWrapper()
      ->addModuleDependencies($modules);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CalculateEntityDependenciesEvent::$stack protected property The dependency stack.
CalculateEntityDependenciesEvent::$wrapper protected property The wrapper of the entity for which we are calculating dependencies.
CalculateEntityDependenciesEvent::addDependency public function Add a dependency to this wrapper.
CalculateEntityDependenciesEvent::getDependencies public function A list of all uuids this entity is dependent on.
CalculateEntityDependenciesEvent::getEntity public function Get the entity for which dependencies are being calculated.
CalculateEntityDependenciesEvent::getModuleDependencies public function A list of modules this entity depends upon.
CalculateEntityDependenciesEvent::getStack public function Get the dependency stack.
CalculateEntityDependenciesEvent::getWrapper public function Get the dependency wrapper of the entity.
CalculateEntityDependenciesEvent::setDependencies public function Add a group of dependencies to this wrapper.
CalculateEntityDependenciesEvent::setModuleDependencies public function A list of module dependencies to add to this wrapper.
CalculateEntityDependenciesEvent::__construct public function CalculateEntityDependenciesEvent constructor.