-
Notifications
You must be signed in to change notification settings - Fork 204
Description
Package containing the bug
next-drupal (NPM package)
Describe the bug
A clear and concise description of what the bug is.
When using next-drupal to create a Media entity of type image, it is not possible to add the meta.alt property to the field_media_image relationship.
The JSON:API specification and Drupal both support meta in relationships.data, and this is required to provide an alt text for images. However, the current TypeScript interface (JsonApiResourceBodyRelationship) does not allow meta, which prevents setting alt.
Expected behavior
I expected to be able to set the alt text when creating a Media Image using createResource, for example:
relationships: {
field_media_image: {
data: {
type: "file--file",
id: file.id,
meta: { alt: "My alt text" }
}
}
}
Steps to reproduce:
Use createResource to create a Media Image entity.
Try to include meta.alt in the field_media_image relationship.
TypeScript throws an error because JsonApiResourceBodyRelationship does not allow meta.
The same request works fine if sent directly to Drupal JSON:API with cURL:
curl -X POST "https://your-drupal-site/jsonapi/media/image" \
-H "Content-Type: application/vnd.api+json" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-d '{
"data": {
"type": "media--image",
"attributes": {
"name": "Example image"
},
"relationships": {
"field_media_image": {
"data": {
"type": "file--file",
"id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"meta": {
"alt": "Accessible description of the image"
}
}
}
}
}
}'
Additional context
JsonApiResourceBodyRelationship is currently defined as:
interface JsonApiResourceBodyRelationship {
data: {
type: string;
id: string;
};
}
This interface should allow an optional meta property so that alt can be passed.
As a workaround, I can send the request manually with fetch or curl, but then I lose the benefits of using createResource.
Sorry for my poor English, my native language is Spanish.