Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ResourceObject.php

function 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.

5 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 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());
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal