trait UrlGeneratorTrait (View source)

deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Url instead.

Wrapper methods for the Url Generator.

This utility trait should only be used in application-level code, such as classes that would implement ContainerInjectionInterface. Services registered in the Container should not use this trait but inject the appropriate service directly for easier testing.

Properties

protected UrlGeneratorInterface $urlGenerator

The url generator.

Methods

string
url($route_name, $route_parameters = [], $options = []) deprecated

Generates a URL or path for a specific route based on the given parameters.

RedirectResponse
redirect(string $route_name, array $route_parameters = [], array $options = [], int $status = 302) deprecated

Returns a redirect response object for the specified route.

getUrlGenerator() deprecated

Returns the URL generator service.

$this
setUrlGenerator(UrlGeneratorInterface $generator) deprecated

Sets the URL generator service.

Details

protected string url($route_name, $route_parameters = [], $options = []) deprecated

deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Url::fromUri() instead.

Generates a URL or path for a specific route based on the given parameters.

For details on the arguments, usage, and possible exceptions see \Drupal\Core\Routing\UrlGeneratorInterface::generateFromRoute().

Parameters

$route_name
$route_parameters
$options

Return Value

string

The generated URL for the given route.

See also

UrlGeneratorInterface::generateFromRoute

protected RedirectResponse redirect(string $route_name, array $route_parameters = [], array $options = [], int $status = 302) deprecated

deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Use new RedirectResponse(Url::fromRoute()) instead.

Returns a redirect response object for the specified route.

Parameters

string $route_name

The name of the route to which to redirect.

array $route_parameters

(optional) Parameters for the route.

array $options

(optional) An associative array of additional options.

int $status

(optional) The HTTP redirect status code for the redirect. The default is 302 Found.

Return Value

RedirectResponse

A redirect response object that may be returned by the controller.

protected UrlGeneratorInterface getUrlGenerator() deprecated

deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Use the url_generator service instead.

Returns the URL generator service.

Return Value

UrlGeneratorInterface

The URL generator service.

$this setUrlGenerator(UrlGeneratorInterface $generator) deprecated

deprecated in drupal:8.0.0 and is removed from drupal:9.0.0.

Sets the URL generator service.

Parameters

UrlGeneratorInterface $generator

The url generator service.

Return Value

$this