You are here

final class NewResourceObject in JSON:API Resources 8

Represents a resource object to be created.

A new resource object does not require many of the arguments required for construction a "regular" resource object. For example, when adding a resource object, an ID is not required.

@internal Do not use this class. It is for internal use and will be phased out when core support for similar behavior exists.

Hierarchy

Expanded class hierarchy of NewResourceObject

1 file declares its use of NewResourceObject
DocumentExtractor.php in src/Unstable/DocumentExtractor.php

File

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

Namespace

Drupal\jsonapi_resources\Unstable\Value
View source
final class NewResourceObject extends ResourceObject {

  /**
   * Creates a new resource object from a decoded JSON:API request's data.
   *
   * @param \Drupal\jsonapi\ResourceType\ResourceType $resource_type
   *   The resource type of the resource object to be created.
   * @param 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 \Drupal\jsonapi_resources\Unstable\Value\NewResourceObject
   *   A new resource object.
   */
  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([]));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CacheableDependencyTrait::$cacheContexts protected property Cache contexts.
CacheableDependencyTrait::$cacheMaxAge protected property Cache max-age.
CacheableDependencyTrait::$cacheTags protected property Cache tags.
CacheableDependencyTrait::getCacheContexts public function 3
CacheableDependencyTrait::getCacheMaxAge public function 3
CacheableDependencyTrait::getCacheTags public function 3
CacheableDependencyTrait::setCacheability protected function Sets cacheability; useful for value object constructors.
NewResourceObject::createFromPrimaryData public static function Creates a new resource object from a decoded JSON:API request's data.
ResourceIdentifierTrait::$resourceIdentifier protected property A ResourceIdentifier object.
ResourceIdentifierTrait::$resourceType protected property The JSON:API resource type of the identified resource object.
ResourceIdentifierTrait::getId public function
ResourceIdentifierTrait::getResourceType public function
ResourceIdentifierTrait::getTypeName public function
ResourceObject::$fields protected property The object's fields.
ResourceObject::$links protected property The resource object's links.
ResourceObject::$versionIdentifier protected property The resource object's version identifier.
ResourceObject::buildLinksFromEntity protected static function Builds a LinkCollection for the given entity.
ResourceObject::createFromEntity public static function Creates a new ResourceObject from an entity. 1
ResourceObject::extractConfigEntityFields protected static function Extracts a config entity's fields.
ResourceObject::extractContentEntityFields protected static function Extracts a content entity's fields.
ResourceObject::extractFieldsFromEntity protected static function Extracts the entity's fields. 1
ResourceObject::getField public function Gets the given field.
ResourceObject::getFields public function Gets the ResourceObject's fields.
ResourceObject::getLabelFieldName protected static function Determines the entity type's (internal) label field name.
ResourceObject::getLinks public function Gets the ResourceObject's links.
ResourceObject::getVersionIdentifier public function Gets a version identifier for the ResourceObject.
ResourceObject::hasField public function Whether the resource object has the given field.
ResourceObject::toUrl public function Gets a Url for the ResourceObject.
ResourceObject::__construct public function ResourceObject constructor.