You are here

public function LayoutBuilderFieldDependencyCollector::onCalculateDependencies in Dependency Calculation 8

Calculates the entities referenced on Layout Builder components.

Parameters

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

Throws

\Drupal\Component\Plugin\Exception\PluginNotFoundException

File

src/EventSubscriber/DependencyCollector/LayoutBuilderFieldDependencyCollector.php, line 33

Class

LayoutBuilderFieldDependencyCollector
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;
  }
  $entity = $event
    ->getEntity();
  if (!$entity instanceof ContentEntityInterface) {
    return;
  }
  $fields = FieldExtractor::getFieldsFromEntity($entity, [
    $this,
    'fieldCondition',
  ]);
  foreach ($fields as $field) {
    foreach ($field as $item) {
      $section = $item
        ->getValue()['section'];
      $this
        ->addSectionDependencies($event, $section);
      $this
        ->addComponentDependencies($event, $section
        ->getComponents());
    }
  }
}