Drupal 8  8.0.2
UnroutedUrlAssembler Class Reference
Inheritance diagram for UnroutedUrlAssembler:

Public Member Functions

 __construct (RequestStack $request_stack, OutboundPathProcessorInterface $path_processor, array $filter_protocols=['http', 'https'])
 
 assemble ($uri, array $options=[], $collect_bubbleable_metadata=FALSE)
 

Protected Member Functions

 buildExternalUrl ($uri, array $options=[], $collect_bubbleable_metadata=FALSE)
 
 buildLocalUrl ($uri, array $options=[], $collect_bubbleable_metadata=FALSE)
 
 addOptionDefaults (array &$options)
 

Protected Attributes

 $requestStack
 
 $pathProcessor
 

Detailed Description

Provides a way to build external or non Drupal local domain URLs.

It takes into account configured safe HTTP protocols.

Constructor & Destructor Documentation

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

Constructs a new unroutedUrlAssembler object.

Parameters
\Symfony\Component\HttpFoundation\RequestStack$request_stackA request stack object.
\Drupal\Core\PathProcessor\OutboundPathProcessorInterface$path_processorThe output path processor.
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

addOptionDefaults ( array &  $options)
protected

Merges in default defaults

Parameters
array$optionsThe options to merge in the defaults.

References Drupal\requestStack().

Referenced by UnroutedUrlAssembler\buildExternalUrl(), and UnroutedUrlAssembler\buildLocalUrl().

Here is the call graph for this function:

Here is the caller graph for this function:

assemble (   $uri,
array  $options = [],
  $collect_bubbleable_metadata = FALSE 
)

{Builds a domain-local or external URL from a URI.For actual implementations the logic probably has to be split up between domain-local URIs and external URLs.

Parameters
string$uriA local URI or an external URL being linked to, such as "base:foo" or "http://example.com/foo".
  • If you provide a full URL, it will be considered an external URL as long as it has an allowed protocol.
  • If you provide only a local URI (e.g. "base:foo"), it will be considered a path local to Drupal, but not handled by the routing system. The base path (the subdirectory where the front controller is found) will be added to the path. Additional query arguments for local paths must be supplied in $options['query'], not part of $uri.
  • If your external URL contains a query (e.g. http://example.com/foo?a=b), then you can either URL encode the query keys and values yourself and include them in $uri, or use $options['query'] to let this method URL encode them.
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.
  • '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.
bool$collect_bubbleable_metadata(optional) Defaults to FALSE. When TRUE, both the generated URL and its associated bubbleable metadata are returned.
Returns
string| A string containing a relative or absolute URL. When $collect_bubbleable_metadata is TRUE, a GeneratedUrl object is returned, containing the generated URL plus bubbleable metadata.
Exceptions
\InvalidArgumentExceptionThrown when the passed in path has no scheme.
}

This is a helper function that calls buildExternalUrl() or buildLocalUrl() based on a check of whether the path is a valid external URL.

Implements UnroutedUrlAssemblerInterface.

References UnroutedUrlAssembler\buildExternalUrl(), UnroutedUrlAssembler\buildLocalUrl(), and UrlHelper\isExternal().

Here is the call graph for this function:

buildExternalUrl (   $uri,
array  $options = [],
  $collect_bubbleable_metadata = FALSE 
)
protected

{}

References UnroutedUrlAssembler\addOptionDefaults(), and UrlHelper\buildQuery().

Referenced by UnroutedUrlAssembler\assemble().

Here is the call graph for this function:

Here is the caller graph for this function:

buildLocalUrl (   $uri,
array  $options = [],
  $collect_bubbleable_metadata = FALSE 
)
protected

{}

References UnroutedUrlAssembler\addOptionDefaults(), UrlHelper\buildQuery(), and Drupal\requestStack().

Referenced by UnroutedUrlAssembler\assemble().

Here is the call graph for this function:

Here is the caller graph for this function:


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