You are here

class WorkflowCollector in Dependency Calculation 8

Subscribes to dependency collection to extract the entity form display.

Hierarchy

  • class \Drupal\depcalc\EventSubscriber\DependencyCollector\BaseDependencyCollector implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of WorkflowCollector

1 string reference to 'WorkflowCollector'
depcalc.services.yml in ./depcalc.services.yml
depcalc.services.yml
1 service uses WorkflowCollector
workflow.dependency_calculator in ./depcalc.services.yml
Drupal\depcalc\EventSubscriber\DependencyCollector\WorkflowCollector

File

src/EventSubscriber/DependencyCollector/WorkflowCollector.php, line 14

Namespace

Drupal\depcalc\EventSubscriber\DependencyCollector
View source
class WorkflowCollector extends BaseDependencyCollector {

  /**
   * Moderation Information
   *
   * @var \Drupal\content_moderation\ModerationInformationInterface
   */
  protected $moderationInfo;

  /**
   * EntityFormDisplayDependencyCollector constructor.
   *
   * @param \Drupal\content_moderation\ModerationInformationInterface|null $moderation_information
   *   The moderation information.
   */
  public function __construct(ModerationInformationInterface $moderation_information = NULL) {
    $this->moderationInfo = $moderation_information;
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events[DependencyCalculatorEvents::CALCULATE_DEPENDENCIES][] = [
      'onCalculateDependencies',
    ];
    return $events;
  }

  /**
   * Calculates the associated workflows.
   *
   * @param \Drupal\depcalc\Event\CalculateEntityDependenciesEvent $event
   *   The dependency calculation event.
   *
   * @throws \Exception
   */
  public function onCalculateDependencies(CalculateEntityDependenciesEvent $event) {
    if (!$this->moderationInfo) {
      return;
    }
    if ($event
      ->getEntity() instanceof ContentEntityInterface) {
      $workflow = $this->moderationInfo
        ->getWorkflowForEntity($event
        ->getEntity());
      if ($workflow) {
        $wrapper = new DependentEntityWrapper($workflow);
        $local_dependencies = [];
        $this
          ->mergeDependencies($wrapper, $event
          ->getStack(), $this
          ->getCalculator()
          ->calculateDependencies($wrapper, $event
          ->getStack(), $local_dependencies));
        $event
          ->addDependency($wrapper);
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BaseDependencyCollector::getCalculator protected function Gets the dependency calculator.
BaseDependencyCollector::mergeDependencies protected function Properly adds dependencies and their modules to a wrapper object.
WorkflowCollector::$moderationInfo protected property Moderation Information
WorkflowCollector::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
WorkflowCollector::onCalculateDependencies public function Calculates the associated workflows.
WorkflowCollector::__construct public function EntityFormDisplayDependencyCollector constructor.