You are here

protected static function ResourceObject::getLabelFieldName in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/jsonapi/src/JsonApiResource/ResourceObject.php \Drupal\jsonapi\JsonApiResource\ResourceObject::getLabelFieldName()
  2. 9 core/modules/jsonapi/src/JsonApiResource/ResourceObject.php \Drupal\jsonapi\JsonApiResource\ResourceObject::getLabelFieldName()

Determines the entity type's (internal) label field name.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity from which fields should be extracted.

Return value

string The label field name.

File

core/modules/jsonapi/src/JsonApiResource/ResourceObject.php, line 341

Class

ResourceObject
Represents a JSON:API resource object.

Namespace

Drupal\jsonapi\JsonApiResource

Code

protected static function getLabelFieldName(EntityInterface $entity) {
  $label_field_name = $entity
    ->getEntityType()
    ->getKey('label');

  // Special handling for user entities that allows a JSON:API user agent to
  // access the display name of a user. This is useful when displaying the
  // name of a node's author.
  // @see \Drupal\jsonapi\JsonApiResource\ResourceObject::extractContentEntityFields()
  // @todo: eliminate this special casing in https://www.drupal.org/project/drupal/issues/3079254.
  if ($entity
    ->getEntityTypeId() === 'user') {
    $label_field_name = 'display_name';
  }
  return $label_field_name;
}