new ResourceTypeAttribute($field_name,
$alias, TRUE,
$has_one);
} // With all fields now aliased, detect any conflicts caused by the
// automatically generated aliases above.
foreach (array_intersect($reserved_field_names,
array_keys($fields)) as $reserved_field_name) { /** @var \Drupal\jsonapi\ResourceType\ResourceTypeField $aliased_reserved_field */
$aliased_reserved_field =
$fields[$reserved_field_name];
/** @var \Drupal\jsonapi\ResourceType\ResourceTypeField $field */
foreach (array_diff_key($fields,
array_flip([$reserved_field_name])) as $field) { if ($aliased_reserved_field->
getPublicName() ===
$field->
getPublicName()) { throw new \
LogicException("The generated alias '{
$aliased_reserved_field->
getPublicName()}' for field name '{
$aliased_reserved_field->
getInternalName()}' conflicts with an existing field. Please report this in the JSON:API issue queue!"
);
} } } // 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_type->
id() === 'user'
) { $fields['display_name'
] =
new ResourceTypeAttribute('display_name'
);
}