You are here

public function EntityPathSubscriber::collectPaths in Tome 8

Reacts to a collect paths event.

Parameters

\Drupal\tome_static\Event\CollectPathsEvent $event: The collect paths event.

File

modules/tome_static/src/EventSubscriber/EntityPathSubscriber.php, line 60

Class

EntityPathSubscriber
Adds entity placeholder paths to the list of paths to export.

Namespace

Drupal\tome_static\EventSubscriber

Code

public function collectPaths(CollectPathsEvent $event) {
  $langcodes = array_keys($this->languageManager
    ->getLanguages());
  $default_langcode = $this->languageManager
    ->getDefaultLanguage()
    ->getId();
  foreach ($this->entityTypeManager
    ->getDefinitions() as $entity_type) {
    if (is_a($entity_type
      ->getClass(), '\\Drupal\\Core\\Entity\\ContentEntityInterface', TRUE) && $entity_type
      ->hasLinkTemplate('canonical')) {
      if ($entity_type
        ->hasLinkTemplate('edit-form') && $entity_type
        ->getLinkTemplate('edit-form') === $entity_type
        ->getLinkTemplate('canonical')) {
        continue;
      }
      $storage = $this->entityTypeManager
        ->getStorage($entity_type
        ->id());
      if ($entity_type
        ->isTranslatable() && ($langcode_key = $entity_type
        ->getKey('langcode'))) {
        foreach ($langcodes as $langcode) {
          foreach ($storage
            ->getQuery()
            ->condition($langcode_key, $langcode)
            ->execute() as $entity_id) {
            $event
              ->addPath(implode(':', [
              static::PLACEHOLDER_PREFIX,
              $entity_type
                ->id(),
              $langcode,
              $entity_id,
            ]), [
              'language_processed' => 'language_processed',
              'langcode' => $langcode,
            ]);
          }
        }
      }
      else {
        foreach ($storage
          ->getQuery()
          ->execute() as $entity_id) {
          $event
            ->addPath(implode(':', [
            static::PLACEHOLDER_PREFIX,
            $entity_type
              ->id(),
            $default_langcode,
            $entity_id,
          ]));
        }
      }
    }
  }
}