Entity reference field View output is not used for selected entity display

Created on 7 September 2016, about 8 years ago
Updated 25 June 2024, 5 months ago

Problem/Motivation

Follow-up for #2174633: View output is not used for entityreference options β†’ : This covers the display of items previously selected in an autocomplete text field.

When the options for selection in an entity auto-complete relation text field are controlled via a view, the view fields are not used to display the selected entity on subsequent edits of the same entity; instead, the entity label is shown. This is a regression from Drupal 7.x.

Expected Results

In step 6, the text in the field should match what was configured in the view, the same way as it appeared when the selection was made in step 4.

Actual Results

In step 6, the text in the field is equal to the entity label, even though that's not the value that was in the field when the selection was made in step 4.

Steps to reproduce

  1. Create a view with an entity reference display and set it up to display more than one field as an inline field.
  2. Add an entity reference field using the auto-complete text field, using the entity reference view display, to a content type.
  3. Visit the node add form.
  4. Fill out the field that was added in step 2; this will show the selected entity as configured in the View (using the selected inline fields).
  5. Save the node
  6. Open the edit back up for editing.
  7. Look at the value that appears in entity reference field that was populated in step 4.

Proposed resolution

TBD

Remaining tasks

Update summary
Clean up MRs

User interface changes

NA

API changes

TBD

Data model changes

TBD

Release notes snippet

NA

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
Entity referenceΒ  β†’

Last updated 1 day ago

No maintainer
Created by

πŸ‡³πŸ‡±Netherlands Lendude Amsterdam

Live updates comments and jobs are added and updated live.
  • VDC

    Related to the Views in Drupal Core initiative.

  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

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

  • πŸ‡«πŸ‡·France dqd London | N.Y.C | Paris | Hamburg | Berlin

    I see all the points and worries but to get forward with this issue and its main focus and primary scope we should prevent to disperse discussion about corners of likes and dislikes in the solution and should minimize the scope as much as possible.

    It is important for custom entities, for big contrib projects like ECK and paragraphs and any data which do not have mandatory title (label) field (and also for the long term future in core since there are discussions about to change the mandatory title field for nodes too) that we get the option at hand to show other than the title field in the edit form after a reference has been selected. -- And from what I understood this issue would solve it.

    Can somebody who is more into this issue, update the summary and can make some notes about what to do next to get forward so that others can chime in to help? Since this issue is a little bit dated it surely needs updates on the to-do list.

  • πŸ‡«πŸ‡·France dqd London | N.Y.C | Paris | Hamburg | Berlin

    More investigating and maybe "good to know" information: For those who use inline_entity_form for creating new entities in the progress of adding them as references can use ief_table_view_mode to get a custom preview of the reference in the edit form display. This solves the problem of entities which have no "label" (title) field looking like empty entries in the preview. Thanks to @mnico for this contribution and important extension for the IEF workflow.

  • Assigned to GuyPaddock
  • πŸ‡ΊπŸ‡ΈUnited States GuyPaddock

    Taking on additional rework.

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

    I reviewed the MR feedback (thank you, @ameymudras). I've ticketed πŸ“Œ Replace \Drupal calls with proper IoC in form elements Active under the #2729597: [meta] Replace \Drupal with injected services where appropriate in core β†’ meta issue. That issue should be appropriately scoped to rework form elements like the Entity Auto-complete text field to use DI. I am moving both \Drupal::service('plugin.manager.entity_reference_selection') calls in the class into a utility method and adding a todo that references #3423053. I believe that to be the most prudent way to avoid bloating the scope of this issue.

    Regarding your feedback, @liquidcms, I agree with what I believe @dqd is saying -- the scope of this issue is to fix what value appears in the autocomplete field when a view is being used to drive selections. The question of whether an ID should be suffixed or not is outside the scope of this issue. The issue you are looking for is πŸ› UX: Hide entity ID in autocomplete widget Needs work and until that issue lands, the implementation in this ticket is consistent with both the way that the ID appears during initial selection with a view as well as autocomplete fields that are not driven by a view.

    As for your other question, @dqd, it seems like you found a solution to your problem with IEF. Regardless, I have cleaned up the issue description to clarify that this issue is specific to autocomplete text fields. Please let me know if that addresses your issue, since IEF is completely separate.

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

    Linking related issues.

  • πŸ‡ΊπŸ‡ΈUnited States GuyPaddock
  • Status changed to Needs review 9 months ago
  • πŸ‡ΊπŸ‡ΈUnited States GuyPaddock

    Just updated the branch for 9.5. My next update will update this for 10.1.x.

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

    Updated for 10.1.x.

  • Issue was unassigned.
  • πŸ‡ΊπŸ‡ΈUnited States GuyPaddock

    Updated for 11.x. Ready for re-review.

  • Pipeline finished with Success
    9 months ago
    Total: 486s
    #101033
  • Status changed to Needs work 9 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Issue summary appears to be missing a few sections

    Added the missing sections but left TBD on sections for someone more familiar with the issue to speak on.

    Also can we hide some of the MRs to just have the intended for 11.x branch. Can be backported later depending when this lands.

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

    Re-roll of MR 2761 against 10.3.x

Production build 0.71.5 2024