W3cubDocs

/Drupal 8

public function UnroutedUrlAssembler::assemble

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

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

Overrides UnroutedUrlAssemblerInterface::assemble

File

core/lib/Drupal/Core/Utility/UnroutedUrlAssembler.php, line 53

Class

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

Namespace

Drupal\Core\Utility

Code

public function assemble($uri, array $options = [], $collect_bubbleable_metadata = FALSE) {
  // Note that UrlHelper::isExternal will return FALSE if the $uri has a
  // disallowed protocol.  This is later made safe since we always add at
  // least a leading slash.
  if (parse_url($uri, PHP_URL_SCHEME) === 'base') {
    return $this->buildLocalUrl($uri, $options, $collect_bubbleable_metadata);
  }
  elseif (UrlHelper::isExternal($uri)) {
    // UrlHelper::isExternal() only returns true for safe protocols.
    return $this->buildExternalUrl($uri, $options, $collect_bubbleable_metadata);
  }
  throw new \InvalidArgumentException("The URI '$uri' is invalid. You must use a valid URI scheme. Use base: for a path, e.g., to a Drupal file that needs the base path. Do not use this for internal paths controlled by Drupal.");
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Utility!UnroutedUrlAssembler.php/function/UnroutedUrlAssembler::assemble/8.1.x