You are here

class LayoutBuilderEntityViewDisplayDependencyCollector in Dependency Calculation 8

Subscribes to dependency collection to extract entities referenced on Layout Builder components.

Hierarchy

Expanded class hierarchy of LayoutBuilderEntityViewDisplayDependencyCollector

1 string reference to 'LayoutBuilderEntityViewDisplayDependencyCollector'
depcalc.services.yml in ./depcalc.services.yml
depcalc.services.yml
1 service uses LayoutBuilderEntityViewDisplayDependencyCollector
layout_builder.entity_view_display.dependency_calculator in ./depcalc.services.yml
Drupal\depcalc\EventSubscriber\DependencyCollector\LayoutBuilderEntityViewDisplayDependencyCollector

File

src/EventSubscriber/DependencyCollector/LayoutBuilderEntityViewDisplayDependencyCollector.php, line 12

Namespace

Drupal\depcalc\EventSubscriber\DependencyCollector
View source
class LayoutBuilderEntityViewDisplayDependencyCollector extends LayoutBuilderDependencyCollectorBase {

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

  /**
   * Calculates the entities referenced in Layout Builder components.
   *
   * @param \Drupal\depcalc\Event\CalculateEntityDependenciesEvent $event
   *   The dependency calculation event.
   *
   * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
   */
  public function onCalculateDependencies(CalculateEntityDependenciesEvent $event) {
    if (!$this->layoutPluginManager) {
      return;
    }

    /** @var \Drupal\Core\Entity\Entity\EntityViewDisplay $entity */
    $entity = $event
      ->getEntity();
    if ($entity
      ->getEntityTypeId() !== 'entity_view_display') {
      return;
    }
    $sections = $entity
      ->getThirdPartySetting('layout_builder', 'sections') ?? [];
    foreach ($sections as $section) {
      $this
        ->addSectionDependencies($event, $section);
      $this
        ->addComponentDependencies($event, $section
        ->getComponents());
    }
  }

}

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.
LayoutBuilderDependencyCollectorBase::$dispatcher protected property The event dispatcher.
LayoutBuilderDependencyCollectorBase::$layoutPluginManager protected property The layout plugin manager.
LayoutBuilderDependencyCollectorBase::addComponentDependencies protected function Adds dependencies from components.
LayoutBuilderDependencyCollectorBase::addSectionComponentEntityDependencies protected function Adds entity dependencies from this layout builder field to this event dependencies.
LayoutBuilderDependencyCollectorBase::addSectionDependencies protected function Set module dependencies to the event.
LayoutBuilderDependencyCollectorBase::__construct public function The LayoutBuilderDependencyCollectorBase constructor.
LayoutBuilderEntityViewDisplayDependencyCollector::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
LayoutBuilderEntityViewDisplayDependencyCollector::onCalculateDependencies public function Calculates the entities referenced in Layout Builder components.