class MetadataBubblingUrlGenerator implements UrlGeneratorInterface (View source)

Decorator for the URL generator, which bubbles bubbleable URL metadata.

Implements a decorator for the URL generator that allows to automatically collect and bubble up bubbleable metadata associated with URLs due to outbound path and route processing. This approach helps keeping the render and the routing subsystems decoupled.

Properties

protected UrlGeneratorInterface $urlGenerator

The non-bubbling URL generator.

protected RendererInterface $renderer

The renderer.

Methods

__construct(UrlGeneratorInterface $url_generator, RendererInterface $renderer)

Constructs a new bubbling URL generator service.

setContext(RequestContext $context)

{@inheritdoc}

getContext()

{@inheritdoc}

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

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

bubble(GeneratedUrl $generated_url, array $options = [])

Bubbles the bubbleable metadata to the current render context.

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.

supports($name)

{@inheritdoc}

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

{@inheritdoc}

Details

__construct(UrlGeneratorInterface $url_generator, RendererInterface $renderer)

Constructs a new bubbling URL generator service.

Parameters

UrlGeneratorInterface $url_generator

The non-bubbling URL generator.

RendererInterface $renderer

The renderer.

setContext(RequestContext $context)

{@inheritdoc}

Parameters

RequestContext $context

getContext()

{@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 bubble(GeneratedUrl $generated_url, array $options = [])

Bubbles the bubbleable metadata to the current render context.

Parameters

GeneratedUrl $generated_url

The generated URL whose bubbleable metadata to bubble.

array $options

(optional) The URL options. Defaults to none.

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

supports($name)

{@inheritdoc}

Parameters

$name

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

{@inheritdoc}

Parameters

$name
array $parameters