class ConfigDependencyCollector in Dependency Calculation 8
Subscribes to layout builder dependency collection to extract config dependencies.
Hierarchy
- class \Drupal\depcalc\EventSubscriber\LayoutBuilderComponentDepencyCollector\ConfigDependencyCollector implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of ConfigDependencyCollector
1 string reference to 'ConfigDependencyCollector'
1 service uses ConfigDependencyCollector
File
- src/
EventSubscriber/ LayoutBuilderComponentDepencyCollector/ ConfigDependencyCollector.php, line 13
Namespace
Drupal\depcalc\EventSubscriber\LayoutBuilderComponentDepencyCollectorView source
class ConfigDependencyCollector implements EventSubscriberInterface {
/**
* The configuration manager.
*
* @var \Drupal\Core\Config\ConfigManagerInterface
*/
protected $configManager;
/**
* ConfigEntityDependencyCollector constructor.
*
* @param \Drupal\Core\Config\ConfigManagerInterface $config_manager
* The configuration manager.
*/
public function __construct(ConfigManagerInterface $config_manager) {
$this->configManager = $config_manager;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[DependencyCalculatorEvents::SECTION_COMPONENT_DEPENDENCIES_EVENT][] = [
'onCalculateSectionComponentDependencies',
];
return $events;
}
/**
* Calculates the entities referenced on Layout Builder components.
*
* @param \Drupal\depcalc\Event\SectionComponentDependenciesEvent $event
* The dependency calculation event.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
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);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigDependencyCollector:: |
protected | property | The configuration manager. | |
ConfigDependencyCollector:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
ConfigDependencyCollector:: |
public | function | Calculates the entities referenced on Layout Builder components. | |
ConfigDependencyCollector:: |
public | function | ConfigEntityDependencyCollector constructor. |