class EntityPathAliasCollector in Dependency Calculation 8
Hierarchy
- class \Drupal\depcalc\EventSubscriber\DependencyCollector\BaseDependencyCollector implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
- class \Drupal\depcalc\EventSubscriber\DependencyCollector\EntityPathAliasCollector
Expanded class hierarchy of EntityPathAliasCollector
1 string reference to 'EntityPathAliasCollector'
1 service uses EntityPathAliasCollector
File
- src/
EventSubscriber/ DependencyCollector/ EntityPathAliasCollector.php, line 11
Namespace
Drupal\depcalc\EventSubscriber\DependencyCollectorView source
class EntityPathAliasCollector extends BaseDependencyCollector {
public static function getSubscribedEvents() {
$events = [];
$events[DependencyCalculatorEvents::CALCULATE_DEPENDENCIES][] = [
'onCalculateDependencies',
];
return $events;
}
public function onCalculateDependencies(CalculateEntityDependenciesEvent $event) {
// @todo remove version condition once 8.7 is no longer supported.
if ($event
->getEntity()
->getEntityTypeId() !== 'path_alias' && version_compare(\Drupal::VERSION, '8.8.0', '>=') && \Drupal::moduleHandler()
->moduleExists('path_alias')) {
$entity = $event
->getEntity();
try {
$uri = "/{$entity->toUrl()->getInternalPath()}";
/** @var \Drupal\path_alias\PathAliasStorage $storage */
$storage = \Drupal::entityTypeManager()
->getStorage('path_alias');
$paths = $storage
->loadByProperties([
'path' => $uri,
]);
if ($paths) {
foreach ($paths as $path) {
$path_wrapper = new DependentEntityWrapper($path);
$path_wrapper
->addDependency($event
->getWrapper(), $event
->getStack());
$local_dependencies = [];
$this
->mergeDependencies($path_wrapper, $event
->getStack(), $this
->getCalculator()
->calculateDependencies($path_wrapper, $event
->getStack(), $local_dependencies));
$event
->addDependency($path_wrapper);
}
}
} catch (EntityMalformedException|UndefinedLinkTemplateException $e) {
return;
}
}
}
}
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. | |
EntityPathAliasCollector:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
EntityPathAliasCollector:: |
public | function |