You are here

public function LayoutBuilderEntityViewDisplayDependencyCollector::onCalculateDependencies in Dependency Calculation 8

Calculates the entities referenced in Layout Builder components.

Parameters

\Drupal\depcalc\Event\CalculateEntityDependenciesEvent $event: The dependency calculation event.

Throws

\Drupal\Component\Plugin\Exception\PluginNotFoundException

File

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

Class

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

Namespace

Drupal\depcalc\EventSubscriber\DependencyCollector

Code

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());
  }
}