class InlineBlockDependencyCollector in Dependency Calculation 8
Subscribes to layout builder dependency collection to extract inline block dependencies.
Hierarchy
- class \Drupal\depcalc\EventSubscriber\LayoutBuilderComponentDepencyCollector\InlineBlockDependencyCollector implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of InlineBlockDependencyCollector
1 string reference to 'InlineBlockDependencyCollector'
1 service uses InlineBlockDependencyCollector
File
- src/
EventSubscriber/ LayoutBuilderComponentDepencyCollector/ InlineBlockDependencyCollector.php, line 14
Namespace
Drupal\depcalc\EventSubscriber\LayoutBuilderComponentDepencyCollectorView source
class InlineBlockDependencyCollector implements EventSubscriberInterface {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* TextItemFieldDependencyCollector constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_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();
if (!$plugin instanceof InlineBlock) {
return;
}
$revision_id = $plugin
->getConfiguration()['block_revision_id'];
$entity = $this->entityTypeManager
->getStorage('block_content')
->loadRevision($revision_id);
$event
->addEntityDependency($entity);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
InlineBlockDependencyCollector:: |
protected | property | The entity type manager. | |
InlineBlockDependencyCollector:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
InlineBlockDependencyCollector:: |
public | function | Calculates the entities referenced on Layout Builder components. | |
InlineBlockDependencyCollector:: |
public | function | TextItemFieldDependencyCollector constructor. |