You are here

public static function ResourceObject::createFromEntity in JSON:API 8.2

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.

12 calls to ResourceObject::createFromEntity()
EntityAccessChecker::getAccessCheckedResourceObject in src/Access/EntityAccessChecker.php
Get the object to normalize and the access based on the provided entity.
EntityReferenceFieldNormalizerTest::testNormalize in tests/src/Kernel/Normalizer/EntityReferenceFieldNormalizerTest.php
@covers ::normalize @dataProvider normalizeProvider
EntityResource::createIndividual in src/Controller/EntityResource.php
Creates an individual entity.
EntityResource::getRelationship in src/Controller/EntityResource.php
Gets the relationship of an entity.
EntityResource::patchIndividual in src/Controller/EntityResource.php
Patches an individual entity.

... See full list

1 method overrides ResourceObject::createFromEntity()
LabelOnlyResourceObject::createFromEntity in src/JsonApiResource/LabelOnlyResourceObject.php
Creates a new ResourceObject from an entity.

File

src/JsonApiResource/ResourceObject.php, line 104

Class

ResourceObject
Represents a JSON:API resource object.

Namespace

Drupal\jsonapi\JsonApiResource

Code

public static function createFromEntity(ResourceType $resource_type, EntityInterface $entity, LinkCollection $links = NULL) {
  return 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([])));
}