Drupal 8  8.0.2
UrlGenerator Class Reference
Inheritance diagram for UrlGenerator:

Public Member Functions

 __construct (RouteProviderInterface $provider, OutboundPathProcessorInterface $path_processor, OutboundRouteProcessorInterface $route_processor, RequestStack $request_stack, array $filter_protocols=['http', 'https'])
 
 setContext (SymfonyRequestContext $context)
 
 getContext ()
 
 setStrictRequirements ($enabled)
 
 isStrictRequirements ()
 
 getPathFromRoute ($name, $parameters=array())
 
 generate ($name, $parameters=array(), $absolute=FALSE)
 
 generateFromRoute ($name, $parameters=array(), $options=array(), $collect_bubbleable_metadata=FALSE)
 
 supports ($name)
 
 getRouteDebugMessage ($name, array $parameters=array())
 

Protected Member Functions

 doGenerate (array $variables, array $defaults, array $tokens, array $parameters, array $query_params, $name)
 
 getInternalPathFromRoute ($name, SymfonyRoute $route, $parameters=array(), $query_params=array())
 
 processPath ($path, &$options=array(), BubbleableMetadata $bubbleable_metadata=NULL)
 
 processRoute ($name, SymfonyRoute $route, array &$parameters, BubbleableMetadata $bubbleable_metadata=NULL)
 
 getRoute ($name)
 

Protected Attributes

 $context
 
 $requestStack
 
 $pathProcessor
 
 $routeProcessor
 
 $decodedChars
 

Detailed Description

Generates URLs from route names and parameters.

Constructor & Destructor Documentation

__construct ( RouteProviderInterface  $provider,
OutboundPathProcessorInterface  $path_processor,
OutboundRouteProcessorInterface  $route_processor,
RequestStack  $request_stack,
array  $filter_protocols = ['http',
'https']   
)

Constructs a new generator object.

Parameters
\Drupal\Core\Routing\RouteProviderInterface$providerThe route provider to be searched for routes.
\Drupal\Core\PathProcessor\OutboundPathProcessorInterface$path_processorThe path processor to convert the system path to one suitable for urls.
\Drupal\Core\RouteProcessor\OutboundRouteProcessorInterface$route_processorThe route processor.
\Symfony\Component\HttpFoundation\RequestStack$request_stackA request stack object.
string[]$filter_protocols (optional) An array of protocols allowed for URL generation.

References Drupal\requestStack(), and UrlHelper\setAllowedProtocols().

Here is the call graph for this function:

Member Function Documentation

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

Substitute the route parameters into the route path.

Note: This code was copied from ::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$variablesThe variables form the compiled route, corresponding to slugs in the route path.
array$defaultsThe defaults from the route.
array$tokensThe tokens from the compiled route.
array$parametersThe route parameters passed to the generator. Parameters that do not match any variables will be added to the result as query parameters.
array$query_paramsQuery parameters passed to the generator as $options['query'].
string$nameThe route name or other identifying string from ::getRouteDebugMessage().
Returns
string The url path, without any base path, including possible query string.
Exceptions
MissingMandatoryParametersExceptionWhen some parameters are missing that are mandatory for the route
InvalidParameterExceptionWhen a parameter value for a placeholder is not correct because it does not match the requirement

Referenced by UrlGenerator\getInternalPathFromRoute().

Here is the caller graph for this function:

generate (   $name,
  $parameters = array(),
  $absolute = FALSE 
)

{}

References UrlGenerator\generateFromRoute().

Here is the call graph for this function:

generateFromRoute (   $name,
  $parameters = array(),
  $options = array(),
  $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 | \Symfony\Component\Routing\Route$nameThe route name or a route object.
array$parametersAn 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.
Returns
string| 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
\Symfony\Component\Routing\Exception\RouteNotFoundExceptionThrown when the named route does not exist.
\Symfony\Component\Routing\Exception\MissingMandatoryParametersExceptionThrown when some parameters are missing that are mandatory for the route.
\Symfony\Component\Routing\Exception\InvalidParameterExceptionThrown when a parameter value for a placeholder is not correct because it does not match the requirement.
}

Implements UrlGeneratorInterface.

References UrlGenerator\getInternalPathFromRoute(), UrlGenerator\getRoute(), UrlGenerator\getRouteDebugMessage(), UrlGenerator\processPath(), and UrlGenerator\processRoute().

Referenced by UrlGenerator\generate().

Here is the call graph for this function:

Here is the caller graph for this function:

getContext ( )

{}

getInternalPathFromRoute (   $name,
SymfonyRoute  $route,
  $parameters = array(),
  $query_params = array() 
)
protected

Gets the path of a route.

Parameters
$nameThe route name or other debug message.
\Symfony\Component\Routing\Route$routeThe route object.
array$parametersAn array of parameters as passed to ::generate().
array$query_paramsAn array of query string parameter, which will get any extra values from $parameters merged in.
Returns
string The url path corresponding to the route, without the base path.

References UrlGenerator\doGenerate().

Referenced by UrlGenerator\generateFromRoute(), and UrlGenerator\getPathFromRoute().

Here is the call graph for this function:

Here is the caller graph for this function:

getPathFromRoute (   $name,
  $parameters = array() 
)

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

Parameters
string | \Symfony\Component\Routing\Route$nameThe route name or a route object.
array$parametersAn array of parameters as passed to ::generate().
Returns
string The internal Drupal path corresponding to the route.
}

Implements UrlGeneratorInterface.

References UrlGenerator\getInternalPathFromRoute(), UrlGenerator\getRoute(), UrlGenerator\getRouteDebugMessage(), and UrlGenerator\processRoute().

Here is the call graph for this function:

getRoute (   $name)
protected

Find the route using the provided route name.

Parameters
string | \Symfony\Component\Routing\Route$nameThe route name or a route object.
Returns
The found route.
Exceptions
\Symfony\Component\Routing\Exception\RouteNotFoundExceptionThrown if there is no route with that name in this repository.
See Also

Referenced by UrlGenerator\generateFromRoute(), and UrlGenerator\getPathFromRoute().

Here is the caller graph for this function:

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

{}

Referenced by UrlGenerator\generateFromRoute(), and UrlGenerator\getPathFromRoute().

Here is the caller graph for this function:

isStrictRequirements ( )

{}

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

Passes the path to a processor manager to allow alterations.

References Drupal\requestStack().

Referenced by UrlGenerator\generateFromRoute().

Here is the call graph for this function:

Here is the caller graph for this function:

processRoute (   $name,
SymfonyRoute  $route,
array &  $parameters,
BubbleableMetadata  $bubbleable_metadata = NULL 
)
protected

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

Parameters
string$nameThe route name.
\Symfony\Component\Routing\Route$routeThe route object to process.
array$parametersAn array of parameters to be passed to the route compiler.
\Drupal\Core\Render\BubbleableMetadata$bubbleable_metadata(optional) Object to collect route processors' bubbleable metadata.

Referenced by UrlGenerator\generateFromRoute(), and UrlGenerator\getPathFromRoute().

Here is the caller graph for this function:

setContext ( SymfonyRequestContext  $context)

{}

setStrictRequirements (   $enabled)

{}

supports (   $name)

{}

Field Documentation

$decodedChars
protected
Initial value:
= [
'%2F',
'/',
]

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

The first two elements are the first two parameters of str_replace(), so if you override this variable you can also use arrays for the encoded and decoded characters.

See Also

The documentation for this class was generated from the following file: