class PathTranslatorEvent in Decoupled Router 8
Same name and namespace in other branches
- 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
- class \Drupal\decoupled_router\PathTranslatorEvent extends \Symfony\Component\HttpKernel\Event\KernelEvent uses StringTranslationTrait
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_routerView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PathTranslatorEvent:: |
protected | property | The path that needs translation. | |
PathTranslatorEvent:: |
private | property | The response. | |
PathTranslatorEvent:: |
public | function | Get the path. | |
PathTranslatorEvent:: |
public | function | Returns the response object. | |
PathTranslatorEvent:: |
public | function | Set the path. | |
PathTranslatorEvent:: |
constant | |||
PathTranslatorEvent:: |
public | function | PathTranslatorEvent constructor. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |