LabelOnlyResourceObject
final class LabelOnlyResourceObject extends ResourceObject (View source)
| internal | JSON:API maintains no PHP API. The API is the HTTP API. This class may change at any time and could break any dependencies on it. |
Value object decorating a ResourceObject; only its label is available.
Traits
Trait for \Drupal\Core\Cache\CacheableDependencyInterface.
Used to associate an object like an exception to a particular resource.
Properties
| protected string[] | $cacheContexts | Cache contexts. |
from CacheableDependencyTrait |
| protected string[] | $cacheTags | Cache tags. |
from CacheableDependencyTrait |
| protected int | $cacheMaxAge | Cache max-age. |
from CacheableDependencyTrait |
| protected ResourceIdentifier | $resourceIdentifier | A ResourceIdentifier object. |
from ResourceIdentifierTrait |
| protected ResourceType | $resourceType | The JSON:API resource type of the identified resource object. |
from ResourceIdentifierTrait |
| protected string|null | $versionIdentifier | The resource object's version identifier. |
from ResourceObject |
| protected FieldItemListInterface[]|array | $fields | The object's fields. |
from ResourceObject |
| protected LinkCollection | $links | The resource object's links. |
from ResourceObject |
| protected EntityInterface | $entity | The entity represented by this resource object. |
Methods
Sets cacheability; useful for value object constructors.
ResourceObject constructor.
Creates a new ResourceObject from an entity.
Whether the resource object has the given field.
Gets the given field.
Extracts the entity's fields.
Builds a LinkCollection for the given entity.
Extracts a content entity's fields.
Determines the entity type's (internal) label field name.
Extracts a config entity's fields.
Gets the decorated entity.
Details
protected $this
setCacheability(CacheableDependencyInterface $cacheability)
Sets cacheability; useful for value object constructors.
getCacheTags()
{@inheritdoc}
getCacheContexts()
{@inheritdoc}
getCacheMaxAge()
{@inheritdoc}
getId()
{@inheritdoc}
getTypeName()
{@inheritdoc}
getResourceType()
{@inheritdoc}
__construct(CacheableDependencyInterface $cacheability, ResourceType $resource_type, string $id, mixed|null $revision_id, array $fields, LinkCollection $links)
ResourceObject constructor.
static ResourceObject
createFromEntity(ResourceType $resource_type, EntityInterface $entity, LinkCollection $links = NULL)
Creates a new ResourceObject from an entity.
bool
hasField(string $public_field_name)
Whether the resource object has the given field.
mixed|FieldItemListInterface|null
getField(string $public_field_name)
Gets the given field.
array
getFields()
Gets the ResourceObject's fields.
LinkCollection
getLinks()
Gets the ResourceObject's links.
string
getVersionIdentifier()
Gets a version identifier for the ResourceObject.
Url
toUrl()
Gets a Url for the ResourceObject.
static protected mixed|FieldItemListInterface[]
extractFieldsFromEntity(ResourceType $resource_type, EntityInterface $entity)
Extracts the entity's fields.
static protected LinkCollection
buildLinksFromEntity(ResourceType $resource_type, EntityInterface $entity, LinkCollection $links)
Builds a LinkCollection for the given entity.
static protected FieldItemListInterface[]
extractContentEntityFields(ResourceType $resource_type, ContentEntityInterface $entity)
Extracts a content entity's fields.
static protected string
getLabelFieldName(EntityInterface $entity)
Determines the entity type's (internal) label field name.
static protected array
extractConfigEntityFields(ResourceType $resource_type, ConfigEntityInterface $entity)
Extracts a config entity's fields.
EntityInterface
getEntity()
Gets the decorated entity.
protected
setEntity(EntityInterface $entity)
Sets the underlying entity.