You are here

protected function EntityResourceBase::createIndividualDataFromEntity in JSON:API Resources 8

Creates a JSON:API resource object from the given entity.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity from which to create a resource object.

bool $check_access: (optional) Whether to check access on the entity or not.

Return value

\Drupal\jsonapi\JsonApiResource\ResourceObjectData A ResourceObjectData object containing a resource object with a cardinality of 1. This corresponds to a top-level document's primary data on an individual response.

See also

\Drupal\jsonapi_resources\Resource\EntityResourceBase::createResourceObjectFromEntities()

File

src/Resource/EntityResourceBase.php, line 71

Class

EntityResourceBase
Defines basic functionality for an entity-oriented JSON:API Resource.

Namespace

Drupal\jsonapi_resources\Resource

Code

protected function createIndividualDataFromEntity(EntityInterface $entity, $check_access = TRUE) : ResourceObjectData {
  $resource_objects = $this
    ->createCollectionDataFromEntities([
    $entity,
  ], $check_access);
  return new ResourceObjectData($resource_objects
    ->toArray(), 1);
}