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.
There was a patch from existing issue which got merged to core, however it creates a new attribute instead of previously used name "full_url" a new name "resolvable_uri" was used. Any websites previously used this field value now need to do data migration. This also complicates things for the sites that uses this attributes in token inserted from wysiwyg editor.
Proposed resolution
Add back 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": [
]
}
]
Also add the ability to set the field item's value by assigning the full_url property.
Remaining tasks
User interface changes
API changes
An additional property full_url is added to LinkItem.
The value of a Link field item may be set by assigning the value of the full_url property, for example:
$entity->field_link->full_url = 'https://www.drupal.org?test_param=test_value#main-content';
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.
Issue fork drupal-3614963
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
saikatewu@gmail.com commentedComment #4
quietone commentedHi, Issues for Drupal core should be targeted to the 'main' branch, our primary development branch. Changes are made on the main branch first, and are then back ported as needed according to the Core change policies. The version the problem was discovered on should be stated in the issue summary Problem/Motivation section. Thanks.
Un-assigning per Assigning ownership of a Drupal core issue.