8.5.x Url.php Url::toString($collect_bubbleable_metadata = FALSE)
8.0.x Url.php Url::toString($collect_bubbleable_metadata = FALSE)
8.1.x Url.php Url::toString($collect_bubbleable_metadata = FALSE)
8.2.x Url.php Url::toString($collect_bubbleable_metadata = FALSE)
8.3.x Url.php Url::toString($collect_bubbleable_metadata = FALSE)
8.4.x Url.php Url::toString($collect_bubbleable_metadata = FALSE)
8.6.x Url.php Url::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.

Return value

string|\Drupal\Core\GeneratedUrl A string URL. When $collect_bubbleable_metadata is TRUE, a GeneratedUrl object is returned, containing the generated URL plus bubbleable metadata.

File

core/lib/Drupal/Core/Url.php, line 748

Class

Url
Defines an object that holds information about a URL.

Namespace

Drupal\Core

Code

public function toString($collect_bubbleable_metadata = FALSE) {
  if ($this->unrouted) {
    return $this
      ->unroutedUrlAssembler()
      ->assemble($this
      ->getUri(), $this
      ->getOptions(), $collect_bubbleable_metadata);
  }
  return $this
    ->urlGenerator()
    ->generateFromRoute($this
    ->getRouteName(), $this
    ->getRouteParameters(), $this
    ->getOptions(), $collect_bubbleable_metadata);
}