You are here

public static function NewResourceObject::createFromPrimaryData in JSON:API Resources 8

Creates a new resource object from a decoded JSON:API request's data.

Parameters

\Drupal\jsonapi\ResourceType\ResourceType $resource_type: The resource type of the resource object to be created.

array $primary_data: The decoded request's primary data. This is *not* denormalized data, rather, it is the raw decoded JSON from the request body that has not yet been denormalized into in-memory objects.

Return value

\Drupal\jsonapi_resources\Unstable\Value\NewResourceObject A new resource object.

1 call to NewResourceObject::createFromPrimaryData()
DocumentExtractor::extractResourceObjectFromRequest in src/Unstable/DocumentExtractor.php
Decodes and builds a resource object from a request body.

File

src/Unstable/Value/NewResourceObject.php, line 36

Class

NewResourceObject
Represents a resource object to be created.

Namespace

Drupal\jsonapi_resources\Unstable\Value

Code

public static function createFromPrimaryData(ResourceType $resource_type, array $primary_data) {
  $id = $primary_data['id'] ?? \Drupal::service('uuid')
    ->generate();
  $fields = array_merge($primary_data['attributes'] ?? [], $primary_data['relationships'] ?? []);
  return new static(new CacheableMetadata(), $resource_type, $id, NULL, $fields, new LinkCollection([]));
}