class PathAliasEntityCollector in Dependency Calculation 8
Hierarchy
- class \Drupal\depcalc\EventSubscriber\DependencyCollector\BaseDependencyCollector implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
- class \Drupal\depcalc\EventSubscriber\DependencyCollector\PathAliasEntityCollector
Expanded class hierarchy of PathAliasEntityCollector
1 string reference to 'PathAliasEntityCollector'
1 service uses PathAliasEntityCollector
File
- src/
EventSubscriber/ DependencyCollector/ PathAliasEntityCollector.php, line 14
Namespace
Drupal\depcalc\EventSubscriber\DependencyCollectorView source
class PathAliasEntityCollector extends BaseDependencyCollector {
/**
* The url matcher.
*
* @var \Symfony\Component\Routing\Matcher\UrlMatcherInterface
*/
protected $matcher;
public static function getSubscribedEvents() {
$events = [];
$events[DependencyCalculatorEvents::CALCULATE_DEPENDENCIES][] = [
'onCalculateDependencies',
];
return $events;
}
public function __construct(UrlMatcherInterface $matcher) {
$this->matcher = $matcher;
}
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')) {
/** @var \Drupal\path_alias\Entity\PathAlias $entity */
$entity = $event
->getEntity();
$params = $this->matcher
->match($entity
->getPath());
foreach ($params['_raw_variables']
->keys() as $parameter) {
if (!empty($params[$parameter]) && $params[$parameter] instanceof EntityInterface) {
$entity_wrapper = new DependentEntityWrapper($params[$parameter]);
$entity_wrapper
->addDependency($event
->getWrapper(), $event
->getStack());
$local_dependencies = [];
$this
->mergeDependencies($entity_wrapper, $event
->getStack(), $this
->getCalculator()
->calculateDependencies($entity_wrapper, $event
->getStack(), $local_dependencies));
$event
->addDependency($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. | |
PathAliasEntityCollector:: |
protected | property | The url matcher. | |
PathAliasEntityCollector:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
PathAliasEntityCollector:: |
public | function | ||
PathAliasEntityCollector:: |
public | function |