function LabelOnlyResourceObject::extractFieldsFromEntity

Same name in other branches
  1. 8.9.x core/modules/jsonapi/src/JsonApiResource/LabelOnlyResourceObject.php \Drupal\jsonapi\JsonApiResource\LabelOnlyResourceObject::extractFieldsFromEntity()
  2. 10 core/modules/jsonapi/src/JsonApiResource/LabelOnlyResourceObject.php \Drupal\jsonapi\JsonApiResource\LabelOnlyResourceObject::extractFieldsFromEntity()
  3. 11.x core/modules/jsonapi/src/JsonApiResource/LabelOnlyResourceObject.php \Drupal\jsonapi\JsonApiResource\LabelOnlyResourceObject::extractFieldsFromEntity()

Overrides ResourceObject::extractFieldsFromEntity

1 call to LabelOnlyResourceObject::extractFieldsFromEntity()
LabelOnlyResourceObject::createFromEntity in core/modules/jsonapi/src/JsonApiResource/LabelOnlyResourceObject.php
Creates a new ResourceObject from an entity.

File

core/modules/jsonapi/src/JsonApiResource/LabelOnlyResourceObject.php, line 66

Class

LabelOnlyResourceObject
Value object decorating a ResourceObject; only its label is available.

Namespace

Drupal\jsonapi\JsonApiResource

Code

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,
    ]);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.