Drupal 8  8.0.2
Url Class Reference
Inheritance diagram for Url:

Public Member Functions

 __construct ($route_name, $route_parameters=array(), $options=array())
 
 toUriString ()
 
 isExternal ()
 
 isRouted ()
 
 getRouteName ()
 
 getRouteParameters ()
 
 setRouteParameters ($parameters)
 
 setRouteParameter ($key, $value)
 
 getOptions ()
 
 getOption ($name)
 
 setOptions ($options)
 
 setOption ($name, $value)
 
 getUri ()
 
 setAbsolute ($absolute=TRUE)
 
 toString ($collect_bubbleable_metadata=FALSE)
 
 toRenderArray ()
 
 getInternalPath ()
 
 access (AccountInterface $account=NULL)
 
 setUrlGenerator (UrlGeneratorInterface $url_generator=NULL)
 
 setUnroutedUrlAssembler (UnroutedUrlAssemblerInterface $url_assembler)
 

Static Public Member Functions

static fromRoute ($route_name, $route_parameters=array(), $options=array())
 
static fromRouteMatch (RouteMatchInterface $route_match)
 
static fromUserInput ($user_input, $options=[])
 
static fromUri ($uri, $options=[])
 
static createFromRequest (Request $request)
 
static renderAccess (array $element)
 

Protected Member Functions

 setUnrouted ()
 
 accessManager ()
 
 urlGenerator ()
 
 unroutedUrlAssembler ()
 

Static Protected Member Functions

static fromEntityUri (array $uri_parts, array $options, $uri)
 
static fromInternalUri (array $uri_parts, array $options)
 
static fromRouteUri (array $uri_parts, array $options, $uri)
 

Protected Attributes

 $urlGenerator
 
 $urlAssembler
 
 $accessManager
 
 $routeName
 
 $routeParameters = array()
 
 $options = array()
 
 $external = FALSE
 
 $unrouted = FALSE
 
 $uri
 
 $internalPath
 

Detailed Description

Defines an object that holds information about a URL.

Constructor & Destructor Documentation

__construct (   $route_name,
  $route_parameters = array(),
  $options = array() 
)

Constructs a new Url object.

In most cases, use Url::fromRoute() or Url::fromUri() rather than constructing Url objects directly in order to avoid ambiguity and make your code more self-documenting.

Parameters
string$route_nameThe name of the route
array$route_parameters(optional) 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. Merged with the parameters array.
  • '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.
See Also
static::fromRoute()
static::fromUri()
Todo:
Update this documentation for non-routed URIs in https://www.drupal.org/node/2346787

Member Function Documentation

access ( AccountInterface  $account = NULL)

Checks this Url object against applicable access check services.

Determines whether the route is accessible or not.

Parameters
\Drupal\Core\Session\AccountInterface$account(optional) Run access checks for this account. Defaults to the current user.
Returns
bool Returns TRUE if the user has access to the url, otherwise FALSE.

References Url\accessManager(), Url\getRouteName(), Url\getRouteParameters(), and Url\isRouted().

Here is the call graph for this function:

accessManager ( )
protected
Returns

References Drupal\service().

Referenced by Url\access(), and TestUrl\setAccessManager().

Here is the call graph for this function:

Here is the caller graph for this function:

static createFromRequest ( Request  $request)
static

Returns the Url object matching a request.

SECURITY NOTE: The request path is not checked to be valid and accessible by the current user to allow storing and reusing Url objects by different users. The 'path.validator' service getUrlIfValid() method should be used instead of this one if validation and access check is desired. Otherwise, 'access_manager' service checkNamedRoute() method should be used on the router name and parameters stored in the Url object returned by this method.

Parameters
\Symfony\Component\HttpFoundation\Request$requestA request object.
Returns
static A Url object. Warning: the object is created even if the current user would get an access denied running the same request via the normal page flow.
Exceptions
\Drupal\Core\Routing\MatchingRouteNotFoundExceptionThrown when the request cannot be matched.

References Drupal\service().

Referenced by ViewEditForm\submitDelayDestination(), UnroutedUrlTest\testCreateFromRequest(), UrlTest\testCreateFromRequest(), UrlTest\testUrlFromRequest(), and UrlTest\testUrlFromRequestInvalid().

Here is the call graph for this function:

Here is the caller graph for this function:

static fromEntityUri ( array  $uri_parts,
array  $options,
  $uri 
)
staticprotected

Create a new Url object for entity URIs.

Parameters
array$uri_partsParts from an URI of the form entity:{entity_type}/{entity_id} as from parse_url().
array$optionsAn array of options, see static::fromUri() for details.
string$uriThe original entered URI.
Returns
A new Url object for an entity's canonical route.
Exceptions
\InvalidArgumentExceptionThrown if the entity URI is invalid.
static fromInternalUri ( array  $uri_parts,
array  $options 
)
staticprotected

Creates a new Url object for 'internal:' URIs.

Important note: the URI minus the scheme can NOT simply be validated by a implementation. The semantics of the 'internal:' URI scheme are different:

  • PathValidatorInterface accepts paths without a leading slash (e.g. 'node/add') as well as 2 special paths: '<front>' and '<none>', which are mapped to the correspondingly named routes.
  • 'internal:' URIs store paths with a leading slash that represents the root — i.e. the front page — (e.g. 'internal:/node/add'), and doesn't have any exceptions.

To clarify, a few examples of path plus corresponding 'internal:' URI:

  • 'node/add' -> 'internal:/node/add'
  • 'node/add?foo=bar' -> 'internal:/node/add?foo=bar'
  • 'node/add#kitten' -> 'internal:/node/add#kitten'
  • '<front>' -> 'internal:/'
  • '<front>foo=bar' -> 'internal:/?foo=bar'
  • '<front>#kitten' -> 'internal:/#kitten'
  • '<none>' -> 'internal:'
  • '<none>foo=bar' -> 'internal:?foo=bar'
  • '<none>#kitten' -> 'internal:#kitten'

Therefore, when using a PathValidatorInterface to validate 'internal:' URIs, we must map:

  • 'internal:' (path component is '') to the special '<none>' path
  • 'internal:/' (path component is '/') to the special '<front>' path
  • 'internal:/some-path' (path component is '/some-path') to 'some-path'
Parameters
array$uri_partsParts from an URI of the form internal:{path} as from parse_url().
array$optionsAn array of options, see static::fromUri() for details.
Returns
A new Url object for a 'internal:' URI.
Exceptions
\InvalidArgumentExceptionThrown when the URI's path component doesn't have a leading slash.

References UrlHelper\isExternal(), and Drupal\pathValidator().

Here is the call graph for this function:

static fromRoute (   $route_name,
  $route_parameters = array(),
  $options = array() 
)
static

Creates a new Url object for a URL that has a Drupal route.

This method is for URLs that have Drupal routes (that is, most pages generated by Drupal). For non-routed local URIs relative to the base path (like robots.txt) use Url::fromUri() with the base: scheme.

Parameters
string$route_nameThe name of the route
array$route_parameters(optional) An associative array of route parameter names and values.
array$options(optional) An associative array of additional URL options, with the following elements:
  • 'query': An array of query key/value-pairs (without any URL-encoding) to append to the URL. Merged with the parameters array.
  • '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.
Returns
A new Url object for a routed (internal to Drupal) URL.
See Also
::fromUserInput()
::fromUri()

Referenced by ViewPreviewForm\actions(), BlockContentController\add(), PathController\adminOverview(), LocalTasksTest\assertLocalTasks(), ForumBlockBase\build(), LanguageBlock\build(), ForumController\buildActionLinks(), CommentLinkBuilder\buildCommentedEntityLinks(), FeedViewBuilder\buildComponents(), ViewsSelection\buildConfigurationForm(), Rearrange\buildForm(), Overview\buildForm(), BanAdmin\buildForm(), NegotiationBrowserForm\buildForm(), NodePreviewForm\buildForm(), SimpletestResultsForm\buildForm(), ViewsForm\buildForm(), ConfigSync\buildForm(), CommentLazyBuilders\buildLinks(), ModulesListForm\buildRow(), LinkFormatter\buildUrl(), NegotiationConfigureForm\configureFormTable(), AjaxTestController\dialog(), AjaxTestController\dialogContents(), ConfigController\diff(), FormErrorHandler\displayErrorMessages(), BlockXssTest\doBlockContentTest(), StandardProfileTest\doFrontPageRdfaTests(), BlockXssTest\doMenuTest(), MenuTest\doMenuTests(), ContentTranslationUITestBase\doTestBasicTranslation(), FrontPageTest\doTestFrontPageViewCacheTags(), MenuRouterTest\doTestHookMenuIntegration(), ContentTranslationUITestBase\doTestTranslationDeletion(), ContentTranslationWorkflowsTest\doTestWorkflows(), BlockXssTest\doViewTest(), DbLogController\eventDetails(), SearchExtraTypeSearch\execute(), ImageStyleEditForm\form(), EntityDisplayModeController\formModeTypeSelection(), ConfigNamesMapper\getBasePath(), CsrfTest\getCurlOptions(), VocabularyListBuilder\getDefaultOperations(), TemporaryStream\getExternalUrl(), ViewEditForm\getFormBucket(), ToolbarItem\getInfo(), CommentLinkBuilderTest\getLinkCombinations(), CommentLinkBuilderTest\getMockNode(), FieldUI\getNextDestination(), ConfigEntityMapper\getOperations(), ConfigNamesMapper\getOperations(), ConfigNamesMapper\getOverviewPath(), EntityFormDisplayEditForm\getOverviewUrl(), EntityViewDisplayEditForm\getOverviewUrl(), LinkApprove\getUrlInfo(), ContactLink\getUrlInfo(), PathPluginBase\getUrlInfo(), DbUpdateController\helpfulLinks(), DbUpdateController\info(), BlockLibraryController\listBlocks(), DefaultExceptionHtmlSubscriber\on401(), DefaultExceptionHtmlSubscriber\on403(), DefaultExceptionHtmlSubscriber\on404(), ThemeTestSubscriber\onRequest(), Theme\postInstallTasks(), Module\postInstallTasks(), RenderElement\preRenderAjaxForm(), ContextualLinks\preRenderLinks(), ManagedFile\processManagedFile(), FieldPluginBaseTest\providerTestRenderAsLinkWithUrlAndOptions(), LinkNotExistingInternalConstraintValidatorTest\providerValidate(), NodeTypeListBuilder\render(), ListingEmpty\render(), EntityDisplayModeListBuilder\render(), ViewEditForm\renderDisplayTop(), Node\renderLink(), DbUpdateController\results(), ImageFormatter\settingsForm(), UpdateSchemaTest\setUp(), UpdatePathTestBase\setUp(), ContentTranslationWorkflowsTest\setupEntity(), BasicAuthTest\testBasicAuth(), SessionAuthenticationTest\testBasicAuthNoSession(), ProcessingTest\testBatchRedirectFinishedCallback(), BlockXssTest\testBlockXss(), ConfirmFormHelperTest\testCancelLinkDestination(), ConfirmFormHelperTest\testCancelLinkRoute(), ConfirmFormHelperTest\testCancelLinkRouteWithParams(), ColorSafePreviewTest\testColorPreview(), ConfirmFormTest\testConfirmFormWithExternalDestination(), ConfigEntityTest\testCRUD(), DateTimeTest\testDateFormatConfiguration(), DeleteTest\testDelete(), DestinationTest\testDestination(), DialogTest\testDialog(), ContextualDynamicContextTest\testDifferentPermissions(), LanguageUrlRewritingTest\testDomainNameNegotiationPort(), FunctionsTest\testDrupalPreRenderLinks(), RenderWebTest\testDrupalRenderFormElements(), EarlyRenderingControllerTest\testEarlyRendering(), ToolbarAdminMenuTest\testExternalLink(), ForumTest\testForum(), UrlTest\testFromRoutedPathWithValidRoute(), UrlTest\testFromRouteFront(), FormTest\testGetFormsCsrfToken(), ConfigEntityMapperTest\testGetOperations(), ConfigNamesMapperTest\testGetOperations(), ViewExecutableTest\testGetUrlWithOverriddenUrl(), ViewExecutableTest\testGetUrlWithPathNoPlaceholders(), ViewExecutableTest\testGetUrlWithPlaceholdersAndArgs(), ViewExecutableTest\testGetUrlWithPlaceholdersAndWithoutArgs(), ViewExecutableTest\testGetUrlWithPlaceholdersAndWithoutArgsAndExceptionValue(), BasicAuthTest\testGlobalLoginFloodControl(), GlossaryTest\testGlossaryView(), FormTest\testInputWithInvalidToken(), LanguageUILanguageNegotiationTest\testLanguageDomain(), UpdateCoreTest\testLanguageModuleUpdate(), CommentLinksTest\testLinkApprove(), CommentLinksTest\testLinkReply(), FunctionsTest\testLinks(), LocalActionTest\testLocalAction(), BasicAuthTest\testLocale(), LocalTasksTest\testLocalTaskBlock(), MenuAccessTest\testMenuBlockLinksAccessCheck(), UpdateCoreTest\testModulePageRegularUpdate(), UpdateCoreTest\testModulePageRunCron(), UpdateCoreTest\testModulePageSecurityUpdate(), UpdateCoreTest\testModulePageUpToDate(), RenderElementTypesTest\testMoreLink(), SearchConfigSettingsFormTest\testMultipleSearchPages(), BlockXssTest\testNoUnexpectedEscaping(), PageCacheTest\testPageCacheAnonymous403404(), PageCacheTest\testPageCacheAnonymousRolePermissions(), BasicAuthTest\testPerUserLoginFloodControl(), LocalTasksTest\testPluginLocalTask(), RebuildTest\testPreserveFormActionAfterAJAX(), TableSelectTest\testProcessTableselectWithLinkTitle(), NodeTranslationUITest\testPublishedStatusNoFields(), AjaxFormCacheTest\testQueryString(), FeedParserTest\testRedirectFeed(), EntityCacheTagsTestBase\testReferencedEntity(), UrlTest\testRenderAccess(), TourCacheTagsTest\testRenderedTour(), RestLinkManagerTest\testRestLinkManagers(), RestLinkManagerTest\testRestLinkManagersNoInstallHook(), SessionAuthenticationTest\testSessionFromBasicAuthenticationDoesNotLeak(), BreadcrumbTest\testSetLinks(), ShortcutLinksTest\testShortcutLinkOrder(), SiteMaintenanceTest\testSiteMaintenance(), UrlTest\testToUriStringForInternal(), TermTranslationTest\testTranslatedBreadcrumbs(), EngineTwigTest\testTwigUrlToString(), BasicAuthTest\testUnauthorizedErrorMessage(), UpdateUploadTest\testUpdateManagerCoreSecurityUpdateMessages(), UpdateUploadTest\testUploadModule(), UrlBubbleableMetadataBubblingTest\testUrlBubbleableMetadataBubbling(), UrlTest\testUrlFromRequest(), RouterTest\testUrlGeneratorFront(), QuickEditLoadingTest\testUserWithoutPermission(), LinkExternalProtocolsConstraintValidatorTest\testValidateIgnoresInternalUrls(), VocabularyUiTest\testVocabularyInterface(), DbLogResourceTest\testWatchdog(), BlockXssTest\testXssInCategory(), SystemController\themesPage(), CommonTestController\typeLinkActiveClass(), LanguageTestController\typeLinkActiveClass(), CacheTestController\urlBubbling(), TwigThemeTestController\urlToStringRender(), and EntityDisplayModeController\viewModeTypeSelection().

static fromRouteMatch ( RouteMatchInterface  $route_match)
static

Creates a new URL object from a route match.

Parameters
\Drupal\Core\Routing\RouteMatchInterface$route_matchThe route match.
Returns
$this

References RouteMatchInterface\getRawParameters(), RouteMatchInterface\getRouteName(), and RouteMatchInterface\getRouteObject().

Referenced by PathBasedBreadcrumbBuilder\build(), ViewUI\getStandardButtons(), PathMatcher\isFrontPage(), and UrlTest\testFromRouteMatch().

Here is the call graph for this function:

Here is the caller graph for this function:

static fromRouteUri ( array  $uri_parts,
array  $options,
  $uri 
)
staticprotected

Creates a new Url object for 'route:' URIs.

Parameters
array$uri_partsParts from an URI of the form route:{route_name};{route_parameters} as from parse_url(), where the path is the route name optionally followed by a ";" followed by route parameters in key=value format with & separators.
array$optionsAn array of options, see static::fromUri() for details.
string$uriThe original passed in URI.
Returns
A new Url object for a 'route:' URI.
Exceptions
\InvalidArgumentExceptionThrown when the route URI does not have a route name.
static fromUri (   $uri,
  $options = [] 
)
static

Creates a new Url object from a URI.

This method is for generating URLs for URIs that:

  • do not have Drupal routes: both external URLs and unrouted local URIs like base:robots.txt
  • do have a Drupal route but have a custom scheme to simplify linking. Currently, there is only the entity: scheme (This allows URIs of the form entity:{entity_type}/{entity_id}. For example: entity:node/1 resolves to the entity.node.canonical route with a node parameter of 1.)

For URLs that have Drupal routes (that is, most pages generated by Drupal), use Url::fromRoute().

Parameters
string$uriThe URI of the resource including the scheme. For user input that may correspond to a Drupal route, use internal: for the scheme. For paths that are known not to be handled by the Drupal routing system (such as static files), use base: for the scheme to get a link relative to the Drupal base path (like the <base> HTML element). For a link to an entity you may use entity:{entity_type}/{entity_id} URIs.
array$options(optional) An associative array of additional URL 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.

Note: the internal: scheme should be avoided except when processing actual user input that may or may not correspond to a Drupal route. Normally use Url::fromRoute() for code linking to any any Drupal page.

You can call access() on the returned object to do access checking.

Returns
A new Url object with properties depending on the URI scheme.
Exceptions
\InvalidArgumentExceptionThrown when the passed in path has no scheme.
See Also
::fromRoute()
::fromUserInput()

Referenced by WebTestBase\assertUrl(), SystemTestController\authorizeInit(), FeedViewBuilder\buildComponents(), UpdateManagerUpdate\buildForm(), Item\buildUri(), ImageStyle\buildUrl(), WebTestBase\buildUrl(), BrowserTestBase\drupalGet(), DbLogController\eventDetails(), ViewEditForm\getDisplayDetails(), TwigExtension\getLink(), SafeMarkupKernelTest\getSafeMarkupUriArgs(), PathValidator\getUrl(), LinkItem\getUrl(), MenuLinkBase\getUrlObject(), DbUpdateController\info(), LinkNotExistingInternalConstraintValidatorTest\providerValidate(), LinkExternalProtocolsConstraintValidatorTest\providerValidate(), UpdateTestBase\refreshUpdateStatus(), DbUpdateController\requirements(), ViewEditForm\save(), UpdateTestBase\standardTests(), UrlTest\testAccessUnrouted(), AddFeedTest\testBasicFeedAddNoTitle(), DenormalizeTest\testBasicFieldDenormalization(), ConfirmFormTest\testConfirmFormWithExternalDestination(), DynamicPageCacheIntegrationTest\testDynamicPageCache(), UrlTest\testEntityUris(), UrlTest\testExternalUrls(), FileEntityFormatterTest\testFormatterFileLink(), FileEntityFormatterTest\testFormatterFileUri(), UrlTest\testFromInvalidInternalUri(), UnroutedUrlTest\testFromInvalidUri(), UrlTest\testFromRoutedPathWithInvalidRoute(), UrlTest\testFromRoutedPathWithValidRoute(), UrlTest\testFromRouteUriWithMissingRouteName(), UnroutedUrlTest\testFromUri(), UrlTest\testFromValidInternalUri(), LinkGeneratorTest\testGenerateExternal(), UnroutedUrlTest\testGetInternalPath(), UnroutedUrlTest\testGetOptions(), UnroutedUrlTest\testGetRouteName(), UrlTest\testGetRouteNameWithExternalUrl(), UnroutedUrlTest\testGetRouteParameters(), UrlTest\testGetRouteParametersWithExternalUrl(), UnroutedUrlTest\testGetUri(), UrlTest\testGetUriForExternalUrl(), LinkGenerationTest\testHookLinkAlter(), UpdateContribTest\testHookUpdateStatusAlter(), SimpleTestBrowserTest\testInternalBrowser(), UrlTest\testInvalidEntityUriParameter(), UnroutedUrlTest\testIsExternal(), UrlTest\testLinkBubbleableMetadata(), FunctionsTest\testLinks(), LinkFieldTest\testLinkTitle(), UrlTest\testLinkXSS(), UpdateCoreTest\testMajorUpdateAvailable(), DenormalizeTest\testMarkFieldForDeletion(), RenderElementTypesTest\testMoreLink(), NodeTest\testNodes(), UpdateContribTest\testNoReleasesAvailable(), NormalizeTest\testNormalize(), UpdateCoreTest\testNormalUpdateAvailable(), DenormalizeTest\testPatchDenormalization(), ReadTest\testRead(), UpdateCoreTest\testSecurityUpdateAvailable(), UnroutedUrlTest\testToString(), UrlTest\testToUriStringForEntity(), UrlTest\testToUriStringForInternal(), UrlTest\testToUriStringForRoute(), DenormalizeTest\testTypeHandling(), UpdateContribTest\testUpdateBaseThemeSecurityUpdate(), UpdateContribTest\testUpdateBrokenFetchURL(), UpdateContribTest\testUpdateContribBasic(), UpdateContribTest\testUpdateContribOrder(), UpdateContribTest\testUpdateShowDisabledThemes(), RouterTest\testUrlGeneratorFront(), EntityResolverTest\testUuidEntityResolver(), DbUpdateController\triggerBatch(), MailToFormatter\viewElements(), UriLinkFormatter\viewElements(), BaseFieldFileFormatterBase\viewElements(), AggregatorTitleFormatter\viewElements(), TelephoneLinkFormatter\viewElements(), ImageFormatter\viewElements(), and ResponsiveImageFormatter\viewElements().

static fromUserInput (   $user_input,
  $options = [] 
)
static

Creates a Url object for a relative URI reference submitted by user input.

Use this method to create a URL for user-entered paths that may or may not correspond to a valid Drupal route.

Parameters
string$user_inputUser input for a link or path. The first character must be one of the following characters:
  • '/': A path within the current site. This path might be to a Drupal route (e.g., '/admin'), to a file (e.g., '/README.txt'), or to something processed by a non-Drupal script (e.g., '/not/a/drupal/page'). If the path matches a Drupal route, then the URL generation will include Drupal's path processors (e.g., language-prefixing and aliasing). Otherwise, the URL generation will just append the passed-in path to Drupal's base path.
  • '?': A query string for the current page or resource.
  • '#': A fragment (jump-link) on the current page or resource. This helps reduce ambiguity for user-entered links and paths, and supports user interfaces where users may normally use auto-completion to search for existing resources, but also may type one of these characters to link to (e.g.) a specific path on the site. (With regard to the URI specification, the user input is treated as a relative URI reference where the relative part is of type path-abempty .)
array$options(optional) An array of options. See Url::fromUri() for details.
Returns
static A new Url object based on user input.
Exceptions
\InvalidArgumentExceptionThrown when the user input does not begin with one of the following characters: '/', '?', or '#'.

Referenced by PathController\adminOverview(), ConfirmFormHelper\buildCancelLink(), ViewEditForm\getDisplayDetails(), ViewListBuilder\getDisplayPaths(), FieldUI\getNextDestination(), DisplayPluginBase\renderMoreLink(), FormTestRedirectForm\submitForm(), UrlTest\testFromInvalidUserInput(), UrlTest\testFromUserInput(), LinkGeneratorTest\testGenerateUrlWithQuotes(), UrlTest\testLinkXSS(), and LocalePathTest\testPathLanguageConfiguration().

Here is the caller graph for this function:

getInternalPath ( )

Returns the internal path (system path) for this route.

This path will not include any prefixes, fragments, or query strings.

Returns
string The internal path for this route.
Exceptions
\UnexpectedValueException.If this is a URI with no corresponding system path.

References Url\getRouteName(), Url\getRouteParameters(), and Url\urlGenerator().

Referenced by LinkGenerator\generate().

Here is the call graph for this function:

Here is the caller graph for this function:

getOption (   $name)

Gets a specific option.

Parameters
string$nameThe name of the option.
Returns
mixed The value for a specific option, or NULL if it does not exist.
getOptions ( )

Returns the URL options.

Returns
array

Referenced by LinkGenerator\generate(), FieldPluginBaseTest\testRenderAsLinkWithUrlAndOptions(), Url\toRenderArray(), and Url\toString().

Here is the caller graph for this function:

getRouteName ( )

Returns the route name.

Returns
string
Exceptions
\UnexpectedValueException.If this is a URI with no corresponding route.

Referenced by Url\access(), Url\getInternalPath(), FieldPluginBaseTest\testRenderAsLinkWithUrlAndOptions(), and Url\toString().

Here is the caller graph for this function:

getRouteParameters ( )

Returns the route parameters.

Returns
array
Exceptions
\UnexpectedValueException.If this is a URI with no corresponding route.

Referenced by Url\access(), Url\getInternalPath(), FieldPluginBaseTest\testRenderAsLinkWithUrlAndOptions(), and Url\toString().

Here is the caller graph for this function:

getUri ( )

Returns the URI value for this Url object.

Only to be used if self::$unrouted is TRUE.

Returns
string A URI not connected to a route. May be an external URL.
Exceptions
\UnexpectedValueExceptionThrown when the URI was requested for a routed URL.

Referenced by Url\toString().

Here is the caller graph for this function:

isExternal ( )

Indicates if this Url is external.

Returns
bool

Referenced by LinkGenerator\generate().

Here is the caller graph for this function:

isRouted ( )

Indicates if this Url has a Drupal route.

Returns
bool

Referenced by Url\access(), LinkGenerator\generate(), and Url\toUriString().

Here is the caller graph for this function:

static renderAccess ( array  $element)
static

Checks a Url render element against applicable access check services.

Parameters
array$elementA render element as returned from ::toRenderArray().
Returns
bool Returns TRUE if the current user has access to the url, otherwise FALSE.

Referenced by UrlTest\testRenderAccess().

Here is the caller graph for this function:

setAbsolute (   $absolute = TRUE)

Sets the value of the absolute option for this Url.

Parameters
bool$absolute(optional) Whether to make this Url absolute or not. Defaults to TRUE.
Returns
$this

Referenced by AuthTest\basicAuthGet().

Here is the caller graph for this function:

setOption (   $name,
  $value 
)

Sets a specific option.

Parameters
string$nameThe name of the option.
mixed$valueThe option value.
Returns
$this
setOptions (   $options)

Sets the URL options.

Parameters
array$optionsThe array of options.
Returns
$this

Referenced by LinkGenerator\generate(), and FieldPluginBaseTest\testRenderAsLinkWithUrlAndOptions().

Here is the caller graph for this function:

setRouteParameter (   $key,
  $value 
)

Sets a specific route parameter.

Parameters
string$keyThe key of the route parameter.
mixed$valueThe route parameter.
Returns
$this
Exceptions
\UnexpectedValueException.If this is a URI with no corresponding route.
setRouteParameters (   $parameters)

Sets the route parameters.

Parameters
array$parametersThe array of parameters.
Returns
$this
Exceptions
\UnexpectedValueException.If this is a URI with no corresponding route.
setUnrouted ( )
protected

Sets this Url to encapsulate an unrouted URI.

Returns
$this
setUnroutedUrlAssembler ( UnroutedUrlAssemblerInterface  $url_assembler)

Sets the unrouted URL assembler.

Parameters
\Drupal\Core\Utility\UnroutedUrlAssemblerInterfaceThe unrouted URL assembler.
Returns
$this
setUrlGenerator ( UrlGeneratorInterface  $url_generator = NULL)

Sets the URL generator.

Parameters
\Drupal\Core\Routing\UrlGeneratorInterface(optional) The URL generator, specify NULL to reset it.
Returns
$this

References Url\urlGenerator().

Referenced by LinkGenerator\generate(), and FieldPluginBaseTest\testRenderAsLinkWithUrlAndOptions().

Here is the call graph for this function:

Here is the caller graph for this function:

toRenderArray ( )

Returns the route information for a render array.

Returns
array An associative array suitable for a render array.

References Url\getOptions().

Here is the call graph for this function:

toString (   $collect_bubbleable_metadata = FALSE)

Generates the string URL representation for this Url object.

For an external URL, the string will contain the input plus any query string or fragment specified by the options array.

If this Url object was constructed from a Drupal route or from an internal URI (URIs using the internal:, base:, or entity: schemes), the returned string will either be a relative URL like /node/1 or an absolute URL like http://example.com/node/1 depending on the options array, plus any specified query string or fragment.

Parameters
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 URL. When $collect_bubbleable_metadata is TRUE, a GeneratedUrl object is returned, containing the generated URL plus bubbleable metadata.

References Url\getOptions(), Url\getRouteName(), Url\getRouteParameters(), Url\getUri(), Url\unroutedUrlAssembler(), and Url\urlGenerator().

Referenced by AuthTest\basicAuthGet(), and LinkGenerator\generate().

Here is the call graph for this function:

Here is the caller graph for this function:

toUriString ( )

Generates a URI string that represents tha data in the Url object.

The URI will typically have the scheme of route: even if the object was constructed using an entity: or internal: scheme. A internal: URI that does not match a Drupal route with be returned here with the base: scheme, and external URLs will be returned in their original form.

Returns
string A URI representation of the Url object data.

References UrlHelper\buildQuery(), and Url\isRouted().

Here is the call graph for this function:

unroutedUrlAssembler ( )
protected

Gets the unrouted URL assembler for non-Drupal URLs.

Returns
The unrouted URL assembler.

References Drupal\service().

Referenced by Url\toString().

Here is the call graph for this function:

Here is the caller graph for this function:

urlGenerator ( )
protected

Gets the URL generator.

Returns
The URL generator.

References Drupal\urlGenerator().

Referenced by Url\getInternalPath(), Url\setUrlGenerator(), and Url\toString().

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: