Entity reference field type, widgets & formatters

Created on 28 September 2023, about 1 year ago
Updated 14 February 2024, 10 months ago

Problem/Motivation

We don't currently support entity reference field types. This feature would truly eliminate unnecessary entity wrapping elements such as paragraphs and blocks if we can integrate this into custom field.

Proposed resolution

Create 2 field types for simplicity: entity_reference_content & entity_reference_config
Create widgets: entity_reference_autocomplete
Create formatters: entity_reference_id, entity_reference_label, entity_reference_entity
Update config schema
Reverse engineer core functions (where necessary) to support selection handler plugins
Tests!

Remaining tasks

Start initial patch to test against.

User interface changes

Storage settings will have 2 new field types.

✨ Feature request
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States apmsooner

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

Merge Requests

Comments & Activities

  • Issue created by @apmsooner
  • πŸ‡ΊπŸ‡ΈUnited States apmsooner

    Recursive rendering risks are currently a blocker for the entity formatter plugin. This is currently a very challenging problem to solve.

    If entity A references entity B and entity B references entity A, the entity formatter will try to render entity A > rendering B > rendering A... that results in an infinite loop that will ultimately crash a page. This feature is on hold until an adequate solution provides support for this edge case. I may roll this out at some point without the entity formatter just to provide decoupled support but hopefully the community may get involved to help this along. Definitely need some solid tests on this one too!

  • Status changed to Needs work about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States apmsooner
  • Status changed to Active about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States dww

    Thanks for opening this issue. I haven't started playing with custom_field, but knowing it doesn't yet support entity reference is a big disappointment, since most of the initial use-cases I imagined for this would involve at least some references. I might be able to help here, if this otherwise ends up being a good solution for some projects I'm working on in the near future...

    If there's no code started, this is still "Active". "Needs work" is for once there's something proposed, but it needs improvement before it could be committed.

    Also, generally we only use "Assigned" if you're personally actively working on something and don't expect anyone else to do anything. Is that true? Are you getting an initial MR together, even if it can potentially be broken via infinite recursion in the edge case you describe? Or is this still at the design phase? I'd unassign yourself if you want other folks to participate.

    In terms of the proposed resolution, I'm not sure why we have to re-implement all the formatters and widgets? Can't we allow any existing formatters and widgets that support entity_reference? That said, I haven't started looking at the code here, so I'm not sure what's happening "under the hood".

    Thanks!
    -Derek

  • @apmsooner opened merge request.
  • Issue was unassigned.
  • πŸ‡ΊπŸ‡ΈUnited States apmsooner
  • πŸ‡ΊπŸ‡ΈUnited States apmsooner

    Thanks DWW, I mistakenly just opened an MR against the 1.0x branch so will have to sort this out first ;)

  • Merge request !34Resolve #3390339 "Entity reference field" β†’ (Merged) created by apmsooner
  • πŸ‡³πŸ‡ΏNew Zealand john pitcairn

    Doesn't the standard entityreference formatter already include some protection against recursive rendering?

  • πŸ‡ΊπŸ‡ΈUnited States apmsooner

    @DWW, Okay, theres a MR opened for the work done so far so a patch can be obtained to test out. I'm only supporting content for references in the initial scope to keep it simple as config references can be a whole other headache and not probably a huge benefit to support immediately. Otherwise, alot of the logic is borrowed from core er field to the extent it could be. There are obviously some workarounds to get it to work in the context of this module but it generally works pretty well with the exception of the entity formatter where I just don't have any protection against recursive rendering. I don't know that I fully understand core's solution for this and exactly how to apply similarly here. There's some other stuff left for unit tests, feeds support, etc... but its a start anyhow ;)

  • πŸ‡ΊπŸ‡ΈUnited States apmsooner

    John, yes it does but we are using our own formatter that works with our own plugin for each column of the field so alot of the core functions and such don't work here. We basically have our own plugin system for all the types, widgets, formatters as they pertain to each column value of the field api type.

  • Status changed to Needs work about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States dww

    Fantastic, thanks! Now it needs work. πŸ˜‚

    No time to dig in fully right now, but very excited to see all this.

    Thanks again,
    -Derek

  • πŸ‡ΊπŸ‡ΈUnited States apmsooner

    apmsooner β†’ changed the visibility of the branch 3390339-entity-reference-field to hidden.

  • πŸ‡ΊπŸ‡ΈUnited States apmsooner

    apmsooner β†’ changed the visibility of the branch 3390339-entity-reference-field to active.

  • πŸ‡ΊπŸ‡ΈUnited States apmsooner

    apmsooner β†’ changed the visibility of the branch 2.0.x to hidden.

  • πŸ‡ΊπŸ‡ΈUnited States apmsooner

    apmsooner β†’ changed the visibility of the branch 3390339-entity-reference-field to hidden.

  • πŸ‡ΊπŸ‡ΈUnited States apmsooner

    apmsooner β†’ changed the visibility of the branch 3390339-entity-reference-field to active.

  • Pipeline finished with Skipped
    10 months ago
    #89963
  • Pipeline finished with Skipped
    10 months ago
    #89964
  • Pipeline finished with Skipped
    10 months ago
    #89974
  • Status changed to Fixed 10 months ago
  • πŸ‡ΊπŸ‡ΈUnited States apmsooner

    Marking this fixed for basic support so people can test in the 2.x dev branch and help get this to a release. There are some tasks I'll create separately for known issues and would certainly appreciate help from the community:

    • Recursive rendering risk in Entity Formatter plugin - its an edge case if someone references the parent entity for example.
    • Caching & access - Not fully tested and needs attention here
    • Entity reference tags widget - not yet implemented
    • Entity reference select widget - not yet implemented
    • Generate sample data - not yet implemented
    • Feeds support - not yet implemented
    • Unit/Functional testing - needed
    • Jsonapi support - basic support only and certainly subject to change. Researching how to handle in relationships array and support includes (if even possible)

    Otherwise, the autocomplete widget setup is pretty much the same as other entity reference in core (supports views and autocreate). Please post issues and contributors feel free to reach out to me on slack if you want to help out :)

  • Status changed to Fixed 10 months ago
  • πŸ‡ΊπŸ‡ΈUnited States apmsooner
Production build 0.71.5 2024