You are here

class PathAliasEntityCollector in Dependency Calculation 8

Hierarchy

  • class \Drupal\depcalc\EventSubscriber\DependencyCollector\BaseDependencyCollector implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of PathAliasEntityCollector

1 string reference to 'PathAliasEntityCollector'
depcalc.services.yml in ./depcalc.services.yml
depcalc.services.yml
1 service uses PathAliasEntityCollector
path_alias.dependency.calculator in ./depcalc.services.yml
Drupal\depcalc\EventSubscriber\DependencyCollector\PathAliasEntityCollector

File

src/EventSubscriber/DependencyCollector/PathAliasEntityCollector.php, line 14

Namespace

Drupal\depcalc\EventSubscriber\DependencyCollector
View 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

Namesort descending Modifiers Type Description Overrides
BaseDependencyCollector::getCalculator protected function Gets the dependency calculator.
BaseDependencyCollector::mergeDependencies protected function Properly adds dependencies and their modules to a wrapper object.
PathAliasEntityCollector::$matcher protected property The url matcher.
PathAliasEntityCollector::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
PathAliasEntityCollector::onCalculateDependencies public function
PathAliasEntityCollector::__construct public function