Problem/Motivation
Link fields and menu links are output in JSON:API in the following format:
"field_link": [
{
"uri": "internal:/",
"title": "Home",
"options": [
]
},
{
"uri": "entity:node/5",
"title": "News Center",
"options": [
]
}
]
This isn't very useful for anything consuming the API because it needs to process these links. In most cases the data can't be fetched because it's unknown what node type is being referenced, and so which endpoint to query is unknown. If this was known, then it would require a lot of unnecessary requests to get the links from various bundle endpoints.
Proposed resolution
Add a computed full_url
property at \Drupal\link\Plugin\Field\FieldType\LinkItem::propertyDefinitions()
"field_link": [
{
"uri": "internal:/",
"full_url": '/'"title": "Home",
"options": [
]
},
{
"uri": "entity:node/5",
"full_url": '/node/5'"title": "News Center",
"options": [
]
}
]
Remaining tasks
Review.
RTBC
User interface changes
None
API changes
An additional property full_url
is added to the link item.
Data model changes
Adds a new computed field so no change in the data model.
Release notes snippet
A new property full_url
has been added to the link field to access the generated URL.
Edit.: The new field was going to be called just url
but it caused some twig override issues (see #22,#26,#27 so full_url
was used instead as suggested in #67)