class NullGenerator extends UrlGenerator (View source)

No-op implementation of a Url Generator, needed for backward compatibility.

Properties

protected RouteProviderInterface $provider

The route provider.

from  UrlGenerator
protected RequestContext $context from  UrlGenerator
protected RequestStack $requestStack

A request stack object.

from  UrlGenerator
protected OutboundPathProcessorInterface $pathProcessor

The path processor to convert the system path to one suitable for urls.

from  UrlGenerator
protected OutboundRouteProcessorInterface $routeProcessor

The route processor.

from  UrlGenerator
protected $decodedChars

Overrides characters that will not be percent-encoded in the path segment.

from  UrlGenerator

Methods

__construct(RequestStack $request_stack)

Override the parent constructor.

setContext(RequestContext $context)

{@inheritdoc}

getContext()

{@inheritdoc}

setStrictRequirements($enabled)

{@inheritdoc}

isStrictRequirements()

{@inheritdoc}

string
getPathFromRoute(string|Route $name, array $parameters = [])

Gets the internal path (system path) for a route.

string
doGenerate(array $variables, array $defaults, array $tokens, array $parameters, array $query_params, string $name)

Substitute the route parameters into the route path.

string
getInternalPathFromRoute($name, Route $route, array $parameters = [], array $query_params = [])

Gets the path of a route.

string
generate($name, $parameters = [], $referenceType = self::ABSOLUTE_PATH)

{@inheritdoc}

string|GeneratedUrl
generateFromRoute(string|Route $name, array $parameters = [], array $options = [], bool $collect_bubbleable_metadata = FALSE)

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

processPath($path, $options = [], BubbleableMetadata $bubbleable_metadata = NULL)

Passes the path to a processor manager to allow alterations.

processRoute(string $name, Route $route, array $parameters, BubbleableMetadata $bubbleable_metadata = NULL)

Passes the route to the processor manager for altering before compilation.

Route
getRoute(string|Route $name)

Find the route using the provided route name.

supports($name)

{@inheritdoc}

getRouteDebugMessage($name, array $parameters = [])

{@inheritdoc}

Details

__construct(RequestStack $request_stack)

Override the parent constructor.

Parameters

RequestStack $request_stack

A request stack object.

setContext(RequestContext $context)

{@inheritdoc}

Parameters

RequestContext $context

getContext()

{@inheritdoc}

setStrictRequirements($enabled)

{@inheritdoc}

Parameters

$enabled

isStrictRequirements()

{@inheritdoc}

string getPathFromRoute(string|Route $name, array $parameters = [])

Gets the internal path (system path) for a route.

Parameters

string|Route $name

The route name or a route object.

array $parameters

An array of parameters as passed to \Symfony\Component\Routing\Generator\UrlGeneratorInterface::generate().

Return Value

string

The internal Drupal path corresponding to the route. This string is not urlencoded and will be an empty string for the front page.

protected string doGenerate(array $variables, array $defaults, array $tokens, array $parameters, array $query_params, string $name)

Substitute the route parameters into the route path.

Note: This code was copied from \Symfony\Component\Routing\Generator\UrlGenerator::doGenerate() and shortened by removing code that is not relevant to Drupal or that is handled separately in ::generateFromRoute(). The Symfony version should be examined for changes in new Symfony releases.

Parameters

array $variables

The variables from the compiled route, corresponding to slugs in the route path.

array $defaults

The defaults from the route.

array $tokens

The tokens from the compiled route.

array $parameters

The route parameters passed to the generator. Parameters that do not match any variables will be added to the result as query parameters.

array $query_params

Query parameters passed to the generator as $options['query']. This may be modified if there are extra parameters not used as route variables.

string $name

The route name or other identifying string from ::getRouteDebugMessage().

Return Value

string

The url path, without any base path, without the query string, not URL encoded.

Exceptions

MissingMandatoryParametersException
InvalidParameterException

protected string getInternalPathFromRoute($name, Route $route, array $parameters = [], array $query_params = [])

Gets the path of a route.

Parameters

$name

The route name or other debug message.

Route $route

The route object.

array $parameters

An array of parameters as passed to \Symfony\Component\Routing\Generator\UrlGeneratorInterface::generate().

array $query_params

An array of query string parameter, which will get any extra values from $parameters merged in.

Return Value

string

The URL path corresponding to the route, without the base path, not URL encoded.

string generate($name, $parameters = [], $referenceType = self::ABSOLUTE_PATH)

{@inheritdoc}

Parameters

$name
$parameters
$referenceType

Return Value

string

string|GeneratedUrl generateFromRoute(string|Route $name, array $parameters = [], array $options = [], bool $collect_bubbleable_metadata = FALSE)

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

Parameters that reference placeholders in the route pattern will be substituted for them in the pattern. Extra params are added as query strings to the URL.

Parameters

string|Route $name

The route name or a route object.

array $parameters

An associative array of parameter names and values.

array $options

(optional) An associative array of additional options, with the following elements:

  • 'query': An array of query key/value-pairs (without any URL-encoding) to append to the URL.
  • 'fragment': A fragment identifier (named anchor) to append to the URL. Do not include the leading '#' character.
  • 'absolute': Defaults to FALSE. Whether to force the output to be an absolute link (beginning with http:). Useful for links that will be displayed outside the site, such as in an RSS feed.
  • 'language': An optional language object used to look up the alias for the URL. If $options['language'] is omitted, it defaults to the current language for the language type LanguageInterface::TYPE_URL.
  • 'https': Whether this URL should point to a secure location. If not defined, the current scheme is used, so the user stays on HTTP or HTTPS respectively. TRUE enforces HTTPS and FALSE enforces HTTP.
  • 'base_url': Only used internally by a path processor, for example, to modify the base URL when a language dependent URL requires so.
  • 'prefix': Only used internally, to modify the path when a language dependent URL requires so.
bool $collect_bubbleable_metadata

(optional) Defaults to FALSE. When TRUE, both the generated URL and its associated bubbleable metadata are returned.

Return Value

string|GeneratedUrl

The generated URL for the given route. When $collect_bubbleable_metadata is TRUE, a GeneratedUrl object is returned, containing the generated URL plus bubbleable metadata.

Exceptions

RouteNotFoundException
MissingMandatoryParametersException
InvalidParameterException

protected processPath($path, $options = [], BubbleableMetadata $bubbleable_metadata = NULL)

Passes the path to a processor manager to allow alterations.

Parameters

$path
$options
BubbleableMetadata $bubbleable_metadata

protected processRoute(string $name, Route $route, array $parameters, BubbleableMetadata $bubbleable_metadata = NULL)

Passes the route to the processor manager for altering before compilation.

Parameters

string $name

The route name.

Route $route

The route object to process.

array $parameters

An array of parameters to be passed to the route compiler.

BubbleableMetadata $bubbleable_metadata

(optional) Object to collect route processors' bubbleable metadata.

protected Route getRoute(string|Route $name)

Find the route using the provided route name.

Parameters

string|Route $name

The route name or a route object.

Return Value

Route

The found route.

Exceptions

RouteNotFoundException

supports($name)

{@inheritdoc}

Parameters

$name

getRouteDebugMessage($name, array $parameters = [])

{@inheritdoc}

Parameters

$name
array $parameters