You are here

class PathTranslatorEvent in Decoupled Router 8

Same name and namespace in other branches
  1. 2.x src/PathTranslatorEvent.php \Drupal\decoupled_router\PathTranslatorEvent

Path translation event.

We don't use GetResponseEvent because we want to initialize the response without stopping propagation.

Hierarchy

Expanded class hierarchy of PathTranslatorEvent

3 files declare their use of PathTranslatorEvent
PathTranslator.php in src/Controller/PathTranslator.php
RedirectPathTranslatorSubscriber.php in src/EventSubscriber/RedirectPathTranslatorSubscriber.php
RouterPathTranslatorSubscriber.php in src/EventSubscriber/RouterPathTranslatorSubscriber.php

File

src/PathTranslatorEvent.php, line 17

Namespace

Drupal\decoupled_router
View source
class PathTranslatorEvent extends KernelEvent {
  use StringTranslationTrait;
  const TRANSLATE = 'decoupled_router.translate_path';

  /**
   * The response.
   *
   * @var \Drupal\Core\Cache\CacheableJsonResponse
   */
  private $response;

  /**
   * The path that needs translation.
   *
   * @var string
   */
  protected $path;

  /**
   * PathTranslatorEvent constructor.
   *
   * @param \Symfony\Component\HttpKernel\HttpKernelInterface $kernel
   *   The kernel.
   * @param \Symfony\Component\HttpFoundation\Request $request
   *   The current request.
   * @param int $requestType
   *   The type of request: master or subrequest.
   * @param string $path
   *   The path to process.
   */
  public function __construct(HttpKernelInterface $kernel, Request $request, $requestType, $path) {
    parent::__construct($kernel, $request, $requestType);
    $this->path = $path;

    // Assume a 404 from start.
    $this->response = CacheableJsonResponse::create([
      'message' => $this
        ->t('Unable to resolve path @path.', [
        '@path' => $path,
      ]),
      'details' => $this
        ->t('None of the available methods were able to find a match for this path.'),
    ], 404);
  }

  /**
   * Get the path.
   *
   * @return string
   *   The path.
   */
  public function getPath() {
    return $this->path;
  }

  /**
   * Set the path.
   *
   * @param string $path
   *   The path.
   */
  public function setPath($path) {
    $this->path = $path;
  }

  /**
   * Returns the response object.
   *
   * @return \Drupal\Core\Cache\CacheableJsonResponse
   *   The response.
   */
  public function getResponse() {
    return $this->response;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PathTranslatorEvent::$path protected property The path that needs translation.
PathTranslatorEvent::$response private property The response.
PathTranslatorEvent::getPath public function Get the path.
PathTranslatorEvent::getResponse public function Returns the response object.
PathTranslatorEvent::setPath public function Set the path.
PathTranslatorEvent::TRANSLATE constant
PathTranslatorEvent::__construct public function PathTranslatorEvent constructor.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.