You are here

public function RedirectPathSubscriber::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/RedirectPathSubscriber.php, line 65

Class

RedirectPathSubscriber
Adds redirect 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());
  $storage = $this->entityTypeManager
    ->getStorage('redirect');
  $langcode_key = $storage
    ->getEntityType()
    ->getKey('langcode');
  $langcodes[] = LanguageInterface::LANGCODE_NOT_SPECIFIED;
  foreach ($langcodes as $langcode) {
    foreach ($storage
      ->getQuery()
      ->condition($langcode_key, $langcode)
      ->execute() as $entity_id) {
      $event
        ->addPath(implode(':', [
        static::PLACEHOLDER_PREFIX,
        $entity_id,
      ]), [
        'language_prefix' => $langcode,
      ]);
    }
  }
}