You are here

trait CalculateDependenciesEventDispatcherTrait in Dependency Calculation 8

Provides a method to dispatch calculate dependencies event.

Hierarchy

File

tests/src/Kernel/EventSubscriber/DependencyCollector/CalculateDependenciesEventDispatcherTrait.php, line 14

Namespace

Drupal\Tests\depcalc\Kernel\EventSubscriber\DependencyCollector
View source
trait CalculateDependenciesEventDispatcherTrait {

  /**
   * Dispatches dependency calculation event.
   *
   * @param \Drupal\Core\Entity\EntityInterface $entity
   *   The entity to use in the event.
   *
   * @return \Drupal\depcalc\Event\CalculateEntityDependenciesEvent
   *   The event.
   *
   * @throws \Exception
   */
  protected function dispatchCalculateDependencies(EntityInterface $entity) : CalculateEntityDependenciesEvent {
    $wrapper = new DependentEntityWrapper($entity);
    $dependencies = new DependencyStack();
    $event = new CalculateEntityDependenciesEvent($wrapper, $dependencies);
    $this->container
      ->get('event_dispatcher')
      ->dispatch(DependencyCalculatorEvents::CALCULATE_DEPENDENCIES, $event);
    return $event;
  }

}

Members