You are here

public static function LabelOnlyResourceObject::createFromEntity in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/jsonapi/src/JsonApiResource/LabelOnlyResourceObject.php \Drupal\jsonapi\JsonApiResource\LabelOnlyResourceObject::createFromEntity()

Creates a new ResourceObject from an entity.

Parameters

\Drupal\jsonapi\ResourceType\ResourceType $resource_type: The JSON:API resource type of the resource object.

\Drupal\Core\Entity\EntityInterface $entity: The entity to be represented by this resource object.

\Drupal\jsonapi\JsonApiResource\LinkCollection $links: (optional) Any links for the resource object, if a `self` link is not provided, one will be automatically added if the resource is locatable and is not an internal entity.

Return value

static An instantiated resource object.

Overrides ResourceObject::createFromEntity

1 call to LabelOnlyResourceObject::createFromEntity()
EntityAccessChecker::getAccessCheckedResourceObject in core/modules/jsonapi/src/Access/EntityAccessChecker.php
Get the object to normalize and the access based on the provided entity.

File

core/modules/jsonapi/src/JsonApiResource/LabelOnlyResourceObject.php, line 30

Class

LabelOnlyResourceObject
Value object decorating a ResourceObject; only its label is available.

Namespace

Drupal\jsonapi\JsonApiResource

Code

public static function createFromEntity(ResourceType $resource_type, EntityInterface $entity, LinkCollection $links = NULL) {
  $resource_object = new static($entity, $resource_type, $entity
    ->uuid(), $resource_type
    ->isVersionable() && $entity instanceof RevisionableInterface ? $entity
    ->getRevisionId() : NULL, static::extractFieldsFromEntity($resource_type, $entity), static::buildLinksFromEntity($resource_type, $entity, $links ?: new LinkCollection([])));
  $resource_object
    ->setEntity($entity);
  return $resource_object;
}