You are here

public function ConfigDependencyCollector::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/ConfigDependencyCollector.php, line 49

Class

ConfigDependencyCollector
Subscribes to layout builder dependency collection to extract config dependencies.

Namespace

Drupal\depcalc\EventSubscriber\LayoutBuilderComponentDepencyCollector

Code

public function onCalculateSectionComponentDependencies(SectionComponentDependenciesEvent $event) {
  $component = $event
    ->getComponent();
  $plugin = $component
    ->getPlugin();
  $config_dependencies = $plugin
    ->getPluginDefinition()['config_dependencies']['config'] ?? [];
  foreach ($config_dependencies as $config_dependency) {
    $config_entity = $this->configManager
      ->loadConfigEntityByName($config_dependency);
    $event
      ->addEntityDependency($config_entity);
  }
}