Evaluate the convenience of the field enhancer AliasLinkEnhancer, given what the JSON:API Extras's UrlLinkEnhancer offers

Created on 22 December 2022, almost 2 years ago
Updated 4 May 2023, over 1 year ago

Problem/Motivation

The field enhancer AliasLinkEnhancer provided by the gatsby_extras module adds the uri_alias key to the data of the Link fields referencing internal entity paths using the "entity:" scheme.

It only takes into account the paths pointing to entities, but it does not cover the other kind of internal paths that use the "internal:" scheme, such as "internal:/" or "internal:/admin/structure" or "internal:/some-path-coming-from-a-view-with-page-display".
Logically, it does not add either the uri_alias key to the links pointing to external URLs.

It provides results like these:

For aliased entities:

"field_link": {
    "uri": "entity:node/12",
    "title": "",
    "options": {
        "attributes": []
    },
    "uri_uuid": "entity:node/article/abc0dff4-ffcd-47b9-b8f6-96ed4e8baxyz",
    "uri_alias": "/article/favorite-webops-tools"
},

For un-aliased entities:

"field_link": {
    "uri": "entity:node/10",
    "title": "",
    "options": {
        "attributes": []
    },
    "uri_uuid": "entity:node/article/abc46f8e-7298-42ac-b5ea-84846d593xyz",
    "uri_alias": "/node/10"
},

For internal non-entity-related paths:
in this case the uri_alias key is not present and the data must be grabbed from the uri key, whose value still relies on the file scheme "internal:", which could be awkward to parse by API consumers.

"field_link": {
    "uri": "internal:/admin/content",
    "title": "",
    "options": {
        "attributes": []
    }
},

For external URLs:
In this case the uri_alias key is not present, so the API consumers must conditionally get the data from uri.

"field_link": {
    "uri": "http://example.com",
    "title": "",
    "options": {
        "attributes": []
    }
},

On the other hand, the JSON:API Extras module offers the enhancer UrlLinkEnhancer that is able to provide a consistent url key for aliased entities, un-aliased entities, internal paths and external URLs.

The enhancer provides results like the ones below (note how the key url is present throughout all the different cases, which is a more consistent method to provide data via an API):

For aliased entities:

"field_link": {
    "uri": "entity:node/12",
    "title": "",
    "options": {
        "attributes": []
    },
    "url": "/article/favorite-webops-tools"
},

For un-aliased entities:

"field_link": {
    "uri": "entity:node/10",
    "title": "",
    "options": {
        "attributes": []
    },
    "url": "/node/10"
},

For internal non-entity-related paths (in this case the uri_alias key is not present):
It offers the relative path to the internal Drupal resource, which is good and easy to parse than "internal:/admin/content"

"field_link": {
    "uri": "internal:/admin/content",
    "title": "",
    "options": {
        "attributes": []
    },
    "url": "/admin/content"
},

For external URLs (in this case the uri_alias key is not present):

"field_link": {
    "uri": "http://example.com",
    "title": "",
    "options": {
        "attributes": []
    },
    "url": "http://example.com"
},

Proposal

Encourage the use of the JSON:API Extras enhancer UrlLinkEnhancer, which currently offers a more comprehensive solution for all the type of resources than can be linked from a Link field.

🌱 Plan
Status

Closed: duplicate

Version

2.0

Component

Code

Created by

πŸ‡¨πŸ‡΄Colombia camilo.escobar

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024