public static function ResourceObject::createFromEntity in Drupal 8
Same name and namespace in other branches
- 9 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.
13 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.
1 method overrides ResourceObject::createFromEntity()
- LabelOnlyResourceObject::createFromEntity in core/
modules/ jsonapi/ src/ JsonApiResource/ LabelOnlyResourceObject.php - Creates a new ResourceObject from an entity.
File
- core/
modules/ jsonapi/ src/ JsonApiResource/ ResourceObject.php, line 105
Class
- ResourceObject
- Represents a JSON:API resource object.
Namespace
Drupal\jsonapi\JsonApiResourceCode
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([])));
}