Quantcast
Viewing all articles
Browse latest Browse all 295107

`link` fields in REST, JSON:API and GraphQL cannot be rendered by client

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 url property at \Drupal\link\Plugin\Field\FieldType\LinkItem::propertyDefinitions()

"field_link": [
  {
    "uri": "internal:/",
    "url": '/'"title": "Home",
    "options": [
    ]
  },
  {
    "uri": "entity:node/5",
    "url": '/node/5'"title": "News Center",
    "options": [
    ]
  }
]

Remaining tasks

Review.
RTBC

User interface changes

None

API changes

An additional property 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 url has been added to the link field to access the generated URL.


Viewing all articles
Browse latest Browse all 295107

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>