Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ResourceObject.php

function 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 217

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.');
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal