abstract class LayoutBuilderDependencyCollectorBase in Dependency Calculation 8
Hierarchy
- class \Drupal\depcalc\EventSubscriber\DependencyCollector\BaseDependencyCollector implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
- class \Drupal\depcalc\EventSubscriber\LayoutBuilderComponentDepencyCollector\LayoutBuilderDependencyCollectorBase
Expanded class hierarchy of LayoutBuilderDependencyCollectorBase
2 files declare their use of LayoutBuilderDependencyCollectorBase
- LayoutBuilderEntityViewDisplayDependencyCollector.php in src/
EventSubscriber/ DependencyCollector/ LayoutBuilderEntityViewDisplayDependencyCollector.php - LayoutBuilderFieldDependencyCollector.php in src/
EventSubscriber/ DependencyCollector/ LayoutBuilderFieldDependencyCollector.php
File
- src/
EventSubscriber/ LayoutBuilderComponentDepencyCollector/ LayoutBuilderDependencyCollectorBase.php, line 14
Namespace
Drupal\depcalc\EventSubscriber\LayoutBuilderComponentDepencyCollectorView source
abstract class LayoutBuilderDependencyCollectorBase extends BaseDependencyCollector {
/**
* The event dispatcher.
*
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
*/
protected $dispatcher;
/**
* The layout plugin manager.
*
* @var \Drupal\Core\Layout\LayoutPluginManager
*/
protected $layoutPluginManager;
/**
* The LayoutBuilderDependencyCollectorBase constructor.
*
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher
* The event dispatcher.
* @param \Drupal\Core\Layout\LayoutPluginManagerInterface|null $layoutPluginManager
* The LayoutPluginManager
*/
public function __construct(EventDispatcherInterface $dispatcher, LayoutPluginManagerInterface $layoutPluginManager = NULL) {
$this->dispatcher = $dispatcher;
$this->layoutPluginManager = $layoutPluginManager;
}
/**
* Set module dependencies to the event.
*
* @param \Drupal\depcalc\Event\CalculateEntityDependenciesEvent $event
* The calculate entity dependencies event.
* @param \Drupal\layout_builder\Section $section
* The section.
*
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
protected function addSectionDependencies(CalculateEntityDependenciesEvent $event, Section $section) {
$layout_id = $section
->getLayoutId();
$layout_plugin_definition = $this->layoutPluginManager
->getDefinition($layout_id);
$event
->setModuleDependencies([
$layout_plugin_definition
->getProvider(),
]);
}
/**
* Adds dependencies from components.
*
* @param \Drupal\depcalc\Event\CalculateEntityDependenciesEvent $event
* The calculate entity dependencies event.
* @param \Drupal\layout_builder\SectionComponent[] $components
* The components for this field.
*
* @throws \Exception
*/
protected function addComponentDependencies(CalculateEntityDependenciesEvent $event, array $components) {
foreach ($components as $component) {
$componentEvent = new SectionComponentDependenciesEvent($component);
$this->dispatcher
->dispatch(DependencyCalculatorEvents::SECTION_COMPONENT_DEPENDENCIES_EVENT, $componentEvent);
$this
->addSectionComponentEntityDependencies($event, $componentEvent
->getEntityDependencies());
$event
->setModuleDependencies($componentEvent
->getModuleDependencies());
}
}
/**
* Adds entity dependencies from this layout builder field to this event
* dependencies.
*
* @param \Drupal\depcalc\Event\CalculateEntityDependenciesEvent $event
* The calculate entity dependencies event.
* @param \Drupal\Core\Entity\EntityInterface[] $entities
* The entity dependencies.
*
* @throws \Exception
*/
protected function addSectionComponentEntityDependencies(CalculateEntityDependenciesEvent $event, array $entities) {
foreach ($entities as $entity) {
$item_entity_wrapper = new DependentEntityWrapper($entity);
$local_dependencies = [];
$this
->mergeDependencies($item_entity_wrapper, $event
->getStack(), $this
->getCalculator()
->calculateDependencies($item_entity_wrapper, $event
->getStack(), $local_dependencies));
$event
->addDependency($item_entity_wrapper);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BaseDependencyCollector:: |
protected | function | Gets the dependency calculator. | |
BaseDependencyCollector:: |
protected | function | Properly adds dependencies and their modules to a wrapper object. | |
LayoutBuilderDependencyCollectorBase:: |
protected | property | The event dispatcher. | |
LayoutBuilderDependencyCollectorBase:: |
protected | property | The layout plugin manager. | |
LayoutBuilderDependencyCollectorBase:: |
protected | function | Adds dependencies from components. | |
LayoutBuilderDependencyCollectorBase:: |
protected | function | Adds entity dependencies from this layout builder field to this event dependencies. | |
LayoutBuilderDependencyCollectorBase:: |
protected | function | Set module dependencies to the event. | |
LayoutBuilderDependencyCollectorBase:: |
public | function | The LayoutBuilderDependencyCollectorBase constructor. |