class RedirectDestination implements RedirectDestinationInterface (View source)

Provides helpers for redirect destinations.

Properties

protected RequestStack $requestStack

The request stack.

protected UrlGeneratorInterface $urlGenerator

The URL generator.

protected string $destination

The destination used by the current request.

Methods

__construct(RequestStack $request_stack, UrlGeneratorInterface $url_generator)

Constructs a new RedirectDestination instance.

array
getAsArray()

Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.

string
get()

Gets the destination as a path.

$this
set(string $new_destination)

Sets the destination as URL.

Details

__construct(RequestStack $request_stack, UrlGeneratorInterface $url_generator)

Constructs a new RedirectDestination instance.

Parameters

RequestStack $request_stack

The request stack.

UrlGeneratorInterface $url_generator

The URL generator.

array getAsArray()

Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.

Used to direct the user back to the referring page after completing a form. By default the current URL is returned. If a destination exists in the current request, that destination is returned. As such, a destination can persist across multiple pages.

Return Value

array

An associative array containing the key:

  • destination: The value of the current request's 'destination' query parameter, if present. This can be either a relative or absolute URL. However, for security, redirection to external URLs is not performed. If the query parameter isn't present, then the URL of the current request is returned.

string get()

Gets the destination as a path.

To convert to a URL suitable for \Symfony\Component\HttpFoundation\RedirectResponse::__construct() use

Return Value

string

$this set(string $new_destination)

Sets the destination as URL.

This method should be used really rarely, for example views uses it, in order to override all destination calls in all of its rendering.

Parameters

string $new_destination

The new destination.

Return Value

$this