Convert the computed path item field type to a regular entity reference field

Created on 20 October 2018, over 6 years ago
Updated 10 February 2025, 2 months ago

Problem/Motivation

After path aliases are converted to a content entity type, we should be able to remove the custom PathItem field type and replace it with a regular entity reference field targeting the new path_alias entity type.

Proposed resolution

Change the relationship between nodes/terms/media items and path aliases to an entity reference one.

Removing the custom path alias related code from various entity forms will most likely need a simple version of Inline Entity Form in core.

Remaining tasks

TBD.

User interface changes

Nope.

API changes

Yes, most likely for REST APIs: getting the path alias for a node will be done by requesting the referenced path alias entity.

Data model changes

A new base field will be added to entity types that support path aliases, currently nodes, taxonomy terms and media items.

📌 Task
Status

Active

Version

11.0 🔥

Component

path.module

Created by

🇷🇴Romania amateescu

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.

  • 🇬🇧United Kingdom joachim

    Will it be able to work exactly like an entity reference field?

    At the moment, the way the API work is that you can save entity data like this:

                'title' => 'Some test data',
                'type' => 'alpha',
                'path' => ['alias' => '/one'],
    

    and the path will get saved.

    So it's not just a case of handling the path alias field widget differently -- the path alias field does magic at the API level too.

    It should definitely behave like a *type* of entity field -- use EntityReferenceItemInterface/EntityReferenceItemBase and EntityReferenceFieldItemListInterface for one thing, and add the 'entity' computed property. But I think it will still to still be its own kind of reference field.

  • 🇬🇧United Kingdom joachim

    There's actually another, more important reason why this can't be a plain reference field: it works backwards compared to normal reference fields.

    With a term reference, say, you do this when saving new entities:

    1. Save the referenced term, so you get an ID for it
    2. Set the ID as the reference field value
    3. Save the referring node

    But with path alias fields, it's the other way round. We have to have the ID of the referring node in order to get the system path to set in the path alias entity. So:

    1. Save the referring node
    2. Get its canonical path, /node/X
    3. Save the path alias, with the canonical path and the alias given in the node's values

Production build 0.71.5 2024