protected static function LabelOnlyResourceObject::extractFieldsFromEntity in JSON:API 8.2
Extracts the entity's fields.
Parameters
\Drupal\jsonapi\ResourceType\ResourceType $resource_type: The JSON:API resource type of the given entity.
\Drupal\Core\Entity\EntityInterface $entity: The entity from which fields should be extracted.
Return value
mixed|\Drupal\Core\Field\FieldItemListInterface[] If the resource object represents a content entity, the fields will be objects satisfying FieldItemListInterface. If it represents a config entity, the fields will be scalar values or arrays.
Overrides ResourceObject::extractFieldsFromEntity
1 call to LabelOnlyResourceObject::extractFieldsFromEntity()
- LabelOnlyResourceObject::createFromEntity in src/
JsonApiResource/ LabelOnlyResourceObject.php - Creates a new ResourceObject from an entity.
File
- src/
JsonApiResource/ LabelOnlyResourceObject.php, line 66
Class
- LabelOnlyResourceObject
- Value object decorating a ResourceObject; only its label is available.
Namespace
Drupal\jsonapi\JsonApiResourceCode
protected static function extractFieldsFromEntity(ResourceType $resource_type, EntityInterface $entity) {
$fields = parent::extractFieldsFromEntity($resource_type, $entity);
$public_label_field_name = $resource_type
->getPublicName(static::getLabelFieldName($entity));
return array_intersect_key($fields, [
$public_label_field_name => TRUE,
]);
}