You are here

protected static function Url::fromEntityUri in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Url.php \Drupal\Core\Url::fromEntityUri()

Create a new Url object for entity URIs.

Parameters

array $uri_parts: Parts from an URI of the form entity:{entity_type}/{entity_id} as from parse_url().

array $options: An array of options, see \Drupal\Core\Url::fromUri() for details.

string $uri: The original entered URI.

Return value

static A new Url object for an entity's canonical route.

Throws

\InvalidArgumentException Thrown if the entity URI is invalid.

1 call to Url::fromEntityUri()
Url::fromUri in core/lib/Drupal/Core/Url.php
Creates a new Url object from a URI.

File

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

Class

Url
Defines an object that holds information about a URL.

Namespace

Drupal\Core

Code

protected static function fromEntityUri(array $uri_parts, array $options, $uri) {
  list($entity_type_id, $entity_id) = explode('/', $uri_parts['path'], 2);
  if ($uri_parts['scheme'] != 'entity' || $entity_id === '') {
    throw new \InvalidArgumentException("The entity URI '{$uri}' is invalid. You must specify the entity id in the URL. e.g., entity:node/1 for loading the canonical path to node entity with id 1.");
  }
  return new static("entity.{$entity_type_id}.canonical", [
    $entity_type_id => $entity_id,
  ], $options);
}