function ResourceIdentifier::fromEntity

Same name in other branches
  1. 8.9.x core/modules/jsonapi/src/JsonApiResource/ResourceIdentifier.php \Drupal\jsonapi\JsonApiResource\ResourceIdentifier::fromEntity()
  2. 10 core/modules/jsonapi/src/JsonApiResource/ResourceIdentifier.php \Drupal\jsonapi\JsonApiResource\ResourceIdentifier::fromEntity()
  3. 11.x core/modules/jsonapi/src/JsonApiResource/ResourceIdentifier.php \Drupal\jsonapi\JsonApiResource\ResourceIdentifier::fromEntity()

Creates a ResourceIdentifier object.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity from which to create the resource identifier.

Return value

self A new ResourceIdentifier object.

1 call to ResourceIdentifier::fromEntity()
EntityAccessDeniedHttpException::__construct in core/modules/jsonapi/src/Exception/EntityAccessDeniedHttpException.php
EntityAccessDeniedHttpException constructor.

File

core/modules/jsonapi/src/JsonApiResource/ResourceIdentifier.php, line 379

Class

ResourceIdentifier
Represents a JSON:API resource identifier object.

Namespace

Drupal\jsonapi\JsonApiResource

Code

public static function fromEntity(EntityInterface $entity) {
    
    /** @var \Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface $resource_type_repository */
    $resource_type_repository = \Drupal::service('jsonapi.resource_type.repository');
    $resource_type = $resource_type_repository->get($entity->getEntityTypeId(), $entity->bundle());
    return new static($resource_type, $entity->uuid());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.