You are here

class CollectPathsEvent in Tome 8

Wraps an array of paths that will be processed by the static generator.

Metadata for paths can also be provided, which can be used to pass data between event subscribers.

If your event subscriber modifies a path, you should set the "original_path" metadata to the untransformed path, if the original path is not already set.

If your event subscriber adds a path that is already multilingual, you should set the "language_processed" metadata to any value, and the "langcode" metadata to the language for the path.

Hierarchy

  • class \Drupal\tome_static\Event\CollectPathsEvent extends \Symfony\Component\EventDispatcher\Event

Expanded class hierarchy of CollectPathsEvent

7 files declare their use of CollectPathsEvent
CollectPathsEventTest.php in modules/tome_static/tests/src/Kernel/CollectPathsEventTest.php
EntityPathSubscriber.php in modules/tome_static/src/EventSubscriber/EntityPathSubscriber.php
ExcludePathSubscriber.php in modules/tome_static/src/EventSubscriber/ExcludePathSubscriber.php
LanguagePathSubscriber.php in modules/tome_static/src/EventSubscriber/LanguagePathSubscriber.php
RedirectPathSubscriber.php in modules/tome_static/src/EventSubscriber/RedirectPathSubscriber.php

... See full list

File

modules/tome_static/src/Event/CollectPathsEvent.php, line 20

Namespace

Drupal\tome_static\Event
View source
class CollectPathsEvent extends Event {

  /**
   * An array mapping path names to metadata.
   *
   * @var array
   */
  protected $paths;

  /**
   * Constructs a CollectPathsEvent object.
   *
   * @param array $paths
   *   An array of paths.
   */
  public function __construct(array $paths) {
    $this->paths = array_fill_keys($paths, []);
  }

  /**
   * Gets the paths.
   *
   * @param bool $with_metadata
   *   Whether or not metadata should be returned. Defaults to FALSE.
   *
   * @return array
   *   An array of paths, or an array mapping path names to metadata.
   */
  public function getPaths($with_metadata = FALSE) {
    return $with_metadata ? $this->paths : array_keys($this->paths);
  }

  /**
   * Adds a single path.
   *
   * @param string $path
   *   A path to add.
   * @param array $metadata
   *   (Optional) Metadata for this path.
   */
  public function addPath($path, array $metadata = []) {
    $this->paths[$path] = $metadata;
  }

  /**
   * Adds multiple paths.
   *
   * @param array $paths
   *   An array of paths, or an array mapping path names to metadata.
   */
  public function addPaths(array $paths) {
    foreach ($paths as $key => $value) {
      if (is_array($value)) {
        $this->paths[$key] = $value;
      }
      else {
        $this->paths[$value] = [];
      }
    }
  }

  /**
   * Replaces a single path.
   *
   * @param string $path
   *   The path to replace.
   * @param string $new_path
   *   The new path.
   * @param array $metadata
   *   (Optional) Metadata for this path.
   */
  public function replacePath($path, $new_path, array $metadata = []) {
    if (isset($this->paths[$path])) {
      unset($this->paths[$path]);
      $this->paths[$new_path] = $metadata;
    }
  }

  /**
   * Replaces all paths.
   *
   * @param array $paths
   *   An array of paths, or an array mapping path names to metadata.
   */
  public function replacePaths(array $paths) {
    $this->paths = [];
    $this
      ->addPaths($paths);
  }

  /**
   * Deletes a single path.
   *
   * @param string $path
   *   A path to delete.
   */
  public function deletePath($path) {
    unset($this->paths[$path]);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CollectPathsEvent::$paths protected property An array mapping path names to metadata.
CollectPathsEvent::addPath public function Adds a single path.
CollectPathsEvent::addPaths public function Adds multiple paths.
CollectPathsEvent::deletePath public function Deletes a single path.
CollectPathsEvent::getPaths public function Gets the paths.
CollectPathsEvent::replacePath public function Replaces a single path.
CollectPathsEvent::replacePaths public function Replaces all paths.
CollectPathsEvent::__construct public function Constructs a CollectPathsEvent object.