class RedirectDestination in Drupal 9
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Routing/RedirectDestination.php \Drupal\Core\Routing\RedirectDestination
Provides helpers for redirect destinations.
Hierarchy
- class \Drupal\Core\Routing\RedirectDestination implements RedirectDestinationInterface
Expanded class hierarchy of RedirectDestination
1 file declares its use of RedirectDestination
- RedirectDestinationTest.php in core/
tests/ Drupal/ Tests/ Core/ Routing/ RedirectDestinationTest.php
1 string reference to 'RedirectDestination'
- core.services.yml in core/
core.services.yml - core/core.services.yml
1 service uses RedirectDestination
File
- core/
lib/ Drupal/ Core/ Routing/ RedirectDestination.php, line 11
Namespace
Drupal\Core\RoutingView source
class RedirectDestination implements RedirectDestinationInterface {
/**
* The request stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected $requestStack;
/**
* The URL generator.
*
* @var \Drupal\Core\Routing\UrlGeneratorInterface
*/
protected $urlGenerator;
/**
* The destination used by the current request.
*
* @var string
*/
protected $destination;
/**
* Constructs a new RedirectDestination instance.
*
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack.
* @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator
* The URL generator.
*/
public function __construct(RequestStack $request_stack, UrlGeneratorInterface $url_generator) {
$this->requestStack = $request_stack;
$this->urlGenerator = $url_generator;
}
/**
* {@inheritdoc}
*/
public function getAsArray() {
return [
'destination' => $this
->get(),
];
}
/**
* {@inheritdoc}
*/
public function get() {
if (!isset($this->destination)) {
$query = $this->requestStack
->getCurrentRequest()->query;
if (UrlHelper::isExternal($query
->get('destination'))) {
$this->destination = '/';
}
elseif ($query
->has('destination')) {
$this->destination = $query
->get('destination');
}
else {
$this->destination = $this->urlGenerator
->generateFromRoute('<current>', [], [
'query' => UrlHelper::filterQueryParameters($query
->all()),
]);
}
}
return $this->destination;
}
/**
* {@inheritdoc}
*/
public function set($new_destination) {
$this->destination = $new_destination;
return $this;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RedirectDestination:: |
protected | property | The destination used by the current request. | |
RedirectDestination:: |
protected | property | The request stack. | |
RedirectDestination:: |
protected | property | The URL generator. | |
RedirectDestination:: |
public | function |
Gets the destination as a path. Overrides RedirectDestinationInterface:: |
|
RedirectDestination:: |
public | function |
Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. Overrides RedirectDestinationInterface:: |
|
RedirectDestination:: |
public | function |
Sets the destination as URL. Overrides RedirectDestinationInterface:: |
|
RedirectDestination:: |
public | function | Constructs a new RedirectDestination instance. |