protected static function ResourceObject::getLabelFieldName in Drupal 9
Same name and namespace in other branches
- 8 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.
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 315
Class
- ResourceObject
- Represents a JSON:API resource object.
Namespace
Drupal\jsonapi\JsonApiResourceCode
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;
}