Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 296477

Reference Field -- Sort By settings -- only shows 1 field label from 1 random bundle

$
0
0

Problem/Motivation

Steps to reproduce this issue:

a) Install with the Standard install profile.

b) Go to Admin > Structure > Content Types.

c) Edit the Article content type -- change its name to Recipe and title field label to Recipe name.

d) Edit the Page content type -- change its name to Vendor and title field label to Vendor name.

[Note: This is similar to the content types used as examples in the User Guide.]

e) Now go to the Recipe content type > Manage fields. Add a Vendor reference field. Or alternatively, go to the Vendor content type and add a Recipe reference field. When you get to the field settings page, you'll see that the title sort option in the "Sort by" select list says "Recipe name" in either case (or it might randomly say "Vendor name" in either case -- I've seen it both ways). Anyway, it is very confusing to say "Recipe name" if you are trying to add a Vendor reference field on the Recipe content type. Here is what the sort options look like:
Sort options for reference field

Proposed resolution

Some points to consider for resolving this issue:

  • One field may have multiple different labels across different bundles. The current code is arbitrarily choosing to display one of the labels and ignoring other labels. But in a simple select list, we cannot really show all of the labels -- there could be a LOT, especially for things like Title that are often labeled differently in different content types.
  • The same label may be used on multiple fields. The current code is only displaying the label (ambiguous), not the field machine name (unambiguous). We need to display the machine name too, or perhaps instead of the label.
  • This is a page that is used by site builders, not content editors, so perhaps displaying only the machine name would make sense -- but on some sites that have been around for a while, certain fields get repurposed and relabeled without changing their machine name, so machine names may not be so intuitive either. Also, removing the label would be disruptive for people who are familiar with the current approach. However, when you're adding a field to a content type, if you want to use an existing field, the Field UI module is already only showing the machine name in that dialog.
  • Similar existing UIs in Core:
    (a) Views -- Add Field/Filter/Sort dialog -- gives you the labels and not the machine names. But it has an entire table with wrapping to put lots of information in, not just a select list.
    Field add dialog in Views

    (b) Field UI -- add existing field for -- what you have in the select list is "Field Type Name: field_machine_name". For example, it says "Entity reference: field_test" for one test field I set up. It does not show the label of the field at all, just the label for the field type.

So... here are some conclusions:
1. We want the machine name to be displayed.
2. We want the label to be displayed. But there could be a lot of labels. So, we need to convey that somehow.
3. We probably want the label(s) first, then machine names, to be least disruptive.
4. The list should be sorted alphabetically.

Formatting options

There are several ways we could format the options. Let's consider each option for the following cases:
C1: Title field, where one content type has it as "Recipe name" and another has it as "Vendor name".
C2: Image field field_image, label "Image", which has subfields of alt, target ID, etc. [see comments #21/22]
C3: Field added in Field UI, with machine name field_foo, with label "Foo" on all content types.

Here are 4 possible options for the option labels:

F1: Patch in #23

- C1:
Recipe name|... [title]
- C2:
Image (alt) [field_image.alt]
Image (target_id) [field_image.target_id]
- C3:
Foo [field_foo]

For this one, we have a patch (#23) and a screenshot. Notice that the highlighted item is an example of (C1):
Sort by list with the patch

F2: Use () for the fields

This is not great -- see also comments #21/22.

- C1:
Recipe name|... (title)
- C2:
Image (alt) (field_image.alt)
Image (target_id) (field_image.target_id)
- C3:
Foo (field_foo)

F3: Separate by :

- C1:
Recipe name|...: title
- C2:
Image (alt): field_image.alt
Image (target_id): field_image.target_id
- C3:
Foo: field_foo

F4: Machine name first with :

- C1:
title: Recipe name|...
- C2:
field_image.alt: Image (alt)
field_image.target_id: Image (target_id)
- C3:
field:foo: Foo

Remaining tasks

  1. Decide on which formatting option is best (F1-F4)
  2. Probably make a different patch to implement it (latest patch is F1)
  3. Does it need a test?

User interface changes

Less confusing labels on the choices for sorting reference fields if there are multiple bundles with different field labels for the same field or multiple fields with the same label. In my experience building web sites for clients, the former is pretty common for the Title field, and somewhat column for other fields, and the second is also fairly common.

Also the choices are sorted for better scanning.

API changes

None.

Data model changes

None. Behind the labels, the machine names of the choices do not change, only the UI.


Viewing all articles
Browse latest Browse all 296477

Trending Articles



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