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
- class \Drupal\jsonapi\JsonApiResource\ResourceObject implements CacheableDependencyInterface, ResourceIdentifierInterface uses CacheableDependencyTrait, ResourceIdentifierTrait
- class \Drupal\jsonapi_resources\Unstable\Value\NewResourceObject
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\ValueView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CacheableDependencyTrait:: |
protected | property | Cache contexts. | |
CacheableDependencyTrait:: |
protected | property | Cache max-age. | |
CacheableDependencyTrait:: |
protected | property | Cache tags. | |
CacheableDependencyTrait:: |
public | function | 3 | |
CacheableDependencyTrait:: |
public | function | 3 | |
CacheableDependencyTrait:: |
public | function | 3 | |
CacheableDependencyTrait:: |
protected | function | Sets cacheability; useful for value object constructors. | |
NewResourceObject:: |
public static | function | Creates a new resource object from a decoded JSON:API request's data. | |
ResourceIdentifierTrait:: |
protected | property | A ResourceIdentifier object. | |
ResourceIdentifierTrait:: |
protected | property | The JSON:API resource type of the identified resource object. | |
ResourceIdentifierTrait:: |
public | function | ||
ResourceIdentifierTrait:: |
public | function | ||
ResourceIdentifierTrait:: |
public | function | ||
ResourceObject:: |
protected | property | The object's fields. | |
ResourceObject:: |
protected | property | The resource object's links. | |
ResourceObject:: |
protected | property | The resource object's version identifier. | |
ResourceObject:: |
protected static | function | Builds a LinkCollection for the given entity. | |
ResourceObject:: |
public static | function | Creates a new ResourceObject from an entity. | 1 |
ResourceObject:: |
protected static | function | Extracts a config entity's fields. | |
ResourceObject:: |
protected static | function | Extracts a content entity's fields. | |
ResourceObject:: |
protected static | function | Extracts the entity's fields. | 1 |
ResourceObject:: |
public | function | Gets the given field. | |
ResourceObject:: |
public | function | Gets the ResourceObject's fields. | |
ResourceObject:: |
protected static | function | Determines the entity type's (internal) label field name. | |
ResourceObject:: |
public | function | Gets the ResourceObject's links. | |
ResourceObject:: |
public | function | Gets a version identifier for the ResourceObject. | |
ResourceObject:: |
public | function | Whether the resource object has the given field. | |
ResourceObject:: |
public | function | Gets a Url for the ResourceObject. | |
ResourceObject:: |
public | function | ResourceObject constructor. |