RedirectDestination.php in Drupal 8
File
core/lib/Drupal/Core/Routing/RedirectDestination.php
View source
<?php
namespace Drupal\Core\Routing;
use Drupal\Component\Utility\UrlHelper;
use Symfony\Component\HttpFoundation\RequestStack;
class RedirectDestination implements RedirectDestinationInterface {
protected $requestStack;
protected $urlGenerator;
protected $destination;
public function __construct(RequestStack $request_stack, UrlGeneratorInterface $url_generator) {
$this->requestStack = $request_stack;
$this->urlGenerator = $url_generator;
}
public function getAsArray() {
return [
'destination' => $this
->get(),
];
}
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;
}
public function set($new_destination) {
$this->destination = $new_destination;
return $this;
}
}