function ResourceObject::createFromEntity

Same name in other branches
  1. 9 core/modules/jsonapi/src/JsonApiResource/ResourceObject.php \Drupal\jsonapi\JsonApiResource\ResourceObject::createFromEntity()
  2. 8.9.x core/modules/jsonapi/src/JsonApiResource/ResourceObject.php \Drupal\jsonapi\JsonApiResource\ResourceObject::createFromEntity()
  3. 10 core/modules/jsonapi/src/JsonApiResource/ResourceObject.php \Drupal\jsonapi\JsonApiResource\ResourceObject::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.

15 calls to ResourceObject::createFromEntity()
EntityAccessChecker::getAccessCheckedResourceObject in core/modules/jsonapi/src/Access/EntityAccessChecker.php
Get the object to normalize and the access based on the provided entity.
EntityResource::createIndividual in core/modules/jsonapi/src/Controller/EntityResource.php
Creates an individual entity.
EntityResource::getRelationship in core/modules/jsonapi/src/Controller/EntityResource.php
Gets the relationship of an entity.
EntityResource::patchIndividual in core/modules/jsonapi/src/Controller/EntityResource.php
Patches an individual entity.
FileUpload::handleFileUploadForNewResource in core/modules/jsonapi/src/Controller/FileUpload.php
Handles JSON:API file upload requests.

... See full list

1 method overrides ResourceObject::createFromEntity()
LabelOnlyResourceObject::createFromEntity in core/modules/jsonapi/src/JsonApiResource/LabelOnlyResourceObject.php

File

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

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([])), $entity->language());
}

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