You are here

public function ResourceObject::toUrl in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/jsonapi/src/JsonApiResource/ResourceObject.php \Drupal\jsonapi\JsonApiResource\ResourceObject::toUrl()

Gets a Url for the ResourceObject.

Return value

\Drupal\Core\Url The URL for the identified resource object.

Throws

\LogicException Thrown if the resource object is not locatable.

See also

\Drupal\jsonapi\ResourceType\ResourceTypeRepository::isLocatableResourceType()

File

core/modules/jsonapi/src/JsonApiResource/ResourceObject.php, line 191

Class

ResourceObject
Represents a JSON:API resource object.

Namespace

Drupal\jsonapi\JsonApiResource

Code

public function toUrl() {
  foreach ($this->links as $key => $link) {
    if ($key === 'self') {
      $first = reset($link);
      return $first
        ->getUri();
    }
  }
  throw new \LogicException('A Url does not exist for this resource object because its resource type is not locatable.');
}