Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ResourceObject.php

function 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.

1 call to ResourceObject::getLabelFieldName()
LabelOnlyResourceObject::extractFieldsFromEntity in core/modules/jsonapi/src/JsonApiResource/LabelOnlyResourceObject.php
Extracts the entity's fields.

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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal