You are here

public function BlockContentDependencyCollector::onCalculateSectionComponentDependencies in Dependency Calculation 8

Calculates the entities referenced on Layout Builder components.

Parameters

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

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

File

src/EventSubscriber/LayoutBuilderComponentDepencyCollector/BlockContentDependencyCollector.php, line 50

Class

BlockContentDependencyCollector
Subscribes to layout builder dependency collection to extract block content dependencies.

Namespace

Drupal\depcalc\EventSubscriber\LayoutBuilderComponentDepencyCollector

Code

public function onCalculateSectionComponentDependencies(SectionComponentDependenciesEvent $event) {
  $component = $event
    ->getComponent();
  $plugin = $component
    ->getPlugin();
  if (!$plugin instanceof BlockContentBlock) {
    return;
  }
  $block_uuid = $plugin
    ->getDerivativeId();
  $entities = $this->entityTypeManager
    ->getStorage('block_content')
    ->loadByProperties([
    'uuid' => $block_uuid,
  ]);
  $entity = array_shift($entities);
  $event
    ->addEntityDependency($entity);
}