Problem/Motivation
I created a field referencing content (formerly called Entity Reference). In the "sort by" selection box, neither "Title" nor the name I had used as override for "Title" (which was "City") appeared in the list.
Strangely enough, I saw the names of overridden title fields for other content types, just not for the content type I was referencing in that case.
Summary Update:
Steps to reproduce:
- Create some content types
- Update the title field label from 'Title' to something else (in all content types including Article and Page).
- Add an entity reference field to any content type, the sort by select list won't have the 'Title' option.
The title field is being shared between content types, at least in the entity reference Sort By select list.
So if the title field label is updated in one or more content types, then chances are that the Sort By select list displays one of the updated labels instead of 'Title'.
So imagine the next scenario w/only two content types:
- Content type one set its title field label to 'title one'
- Content type two set its title field label to 'title two'
- Add an entity reference field to content type one pointing to content type two, and try to sort by title.
The sort by title select list won't display the 'Title' option, instead it would display 'title one' or 'title two' (but only one of those). So if you want to sort the entity reference field pointing to content type two by title, and neither 'Title' or 'title two' are on the Sort By select list it can be confusing.
How are you going to know that the option to select is 'title one' because that corresponds to the title field? In this scenario w/two content types is easy to figure out, but imagine multiple content types and even worst more than one person working in the same project.
Solution Suggested:
For consistency always display 'Title' as an option in the Sort By reference select list instead of any custom title field label.
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | no_title_sort_for-2575259-12.patch | 1.44 KB | blanca.esqueda |
| #8 | ref-field-something-else.jpg | 21.21 KB | extexan |
Issue fork drupal-2575259
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
mikeker commentedCan you give steps to reproduce?
Comment #3
mikeker commentedFor what it's worth, I tried setting up a view was able to sort by a referenced field's label. So, that seems to work fine... If you can export the config files for the content type and view you're using, that would be helpful. Or steps to repro from a clean D8 install.
Comment #4
extexan commented@mikeker,
Thanks for the quick replies. Just to be clear, though, I'm not setting up a view. I'm just creating a reference field on a content type, and trying to sort it (for the auto-complete) on the label field.
More specifically... I have a content type "city". For that one, instead of "Title", I named the label "City".
I then created a content type "destination", and created a field named "Origin City", which was a reference to the "city" content type. When I got down to specifying "sort by", neither "Title" nor "City" were showing in the selection list.
But I have another content type, "country", with label renamed to "Country". When I created the "city" content type, I added a field "Country", which is a reference to the "country" content type. In that case, the "Country" field was in the "sort by" selection list.
Thinking it might be a caching issue, I've tried clearing caches several times, but still no go.
Comment #5
extexan commentedI've tried different things now. I hope this isn't too confusing.
I created "test" content type, with only the body field. "Title" was renamed "Test". I tried to add a field referencing this content type to the "destination" content type. Neither "Title" nor "Test" were in the "sort by" selection. [From now on I'll refer to this as "It didn't work", and if the label field (either as "Title" or the overridden name) appears in the selection list, I will say "It DID work".
I created "test2" content type, with only body field. "Title" was NOT renamed. I tried to add it to the "destination" content type as a reference field. It didn't work.
In the "city" content type, I tried to add a reference to "test2". It didn't work. [So this is an entirely new content type, with no additional fields added, exhibiting the same issue as the "city" content type.]
In the "test2" content type, I added TWO reference fields, one for "country", and one for "city". When I added the reference to "country", the label field (named "Country") WAS in the "sort by" selection list [i.e. it DID work]. For the reference to "city", the label field WAS NOT in the selection list [i.e. it didn't work].
It's almost as if, at a certain point, label stopped showing in the selection list for all content types created after that point.
Comment #6
cilefen commentedHi @ExTexan. Thank you for reporting this. Can we start by getting the steps to reproduce the primary issue in the issue summary? It really helps getting it fixed.
Comment #7
blanca.esqueda commented@ExTexan
Hi, I followed your steps:
And I think you are getting confuse.
You would never see the title field label on the the Sort By selection list, you always would see 'Title'.
The 'Country' that you are seeing in the selection list is not the title field label from your Country content type, instead it is the 'Country' field that you added on your 'City' content type. You can verify this changing the name of either one of those.
'Title' is always on the selection list.
Usually is one of the first options and under the 'Language' option.
Also I tried your second example adding the test and test2 content type and always I was able to find 'Title' on the Sort By selection list.
I tested in a clean D8 installation
This task should be closed, unless you still not able to see the 'Title' option on the Sort By selection list.
Comment #8
extexan commentedAhh, now we're getting somewhere. Thanks everyone for your quick replies, even on (especially on) the weekend. That helped "us" zero in on the issue (and how to reproduce it).
In a (semi)fresh D8 installation, I went to the "Basic page" content type and added a reference to "Article". In that case, "Title" DID appear in the list (just under "Language").
I then went back to the site with the issue, and did the same thing with "Basic page" and "Article". "Title" did NOT appear in the list.
In that site, in addition to "Basic page" and "Article", I have four content types: City, State, Country, and Destination - all with the Title label overridden to be the same as the human-readable content types. I edited each one and changed label back to "Title", then went back to "Basic page" to add a reference to "Article". This time "Title" DID appear in the list (just under "Language" as above).
I then edited the "State" content type and changed the Title to "Something Else", to get away from any conflicts with my Title label being the same as any field I have defined ("Country", for example). Again, adding an "Article" reference to "Basic page", at the same point in the list that I had seen "Title" (under "Language"), I saw "Something Else" (see screenshot).
I then edited the "City" content type and change the Title to "Something Else 2", and added the same reference as before. "Something Else" still appeared in the list (where "Title" should be), but "Something Else 2" was nowhere to be seen.
So it appears that the first content type to have the default label ("Title") overridden shows in the list in place of "Title", but any other overridden labels don't show up. When I originally reported this, the fact that my first overridden content type, "Country", happened to be the same name as one of my fields masked what was happening. That is, two entries named "Country" were being added to the select list, with one overwriting the other (it seems).
Comment #9
blanca.esqueda commented@ExTexan
You right, It is happening!
At first I changed the title field labels for the created content types (Except Article and Page), and I was still seeing 'Title' option on the Sort By selection list. I was going to comment that I wasn't able to replicate it.
But only to be sure, I changed the title field labels for Article and Page content types, and then the Sort By selection list displayed the title field label for the Page content type. I went to review the entity reference fields set previously to sort by 'Title' and they are displaying the custom title field label for the Page content type even when those entity fields point to a different content types.
Entity references still loading the correct values. So I guess keep displaying 'Title' instead of any custom title label field would be the solution.
Comment #10
extexan commentedYes, I just changed all content types back to the default "Title".
I'm just glad we were finally able to zero in on how to replicate it.
Thanks again to everyone.
Comment #11
mikeker commentedOK, nice detective work everyone! :)
Back to active, but I don't believe this is major since there is no major loss of functionality and it's limited in scope. (Admittedly, I just quickly read #8 so I may have missing something...)
If someone could update the issue summary with a short description of the problem and the steps to reproduce, that would be great!
Comment #12
blanca.esqueda commentedIn some way the title field is being share between content types, at least on the entity reference Sort By select list.
As solution and to have consistency the label of the field title always would be displayed as 'Title' to avoid being overridden by any custom title label field.
Comment #13
blanca.esqueda commentedComment #14
blanca.esqueda commentedComment #15
extexan commentedWhile we are in the process of patching the routine that builds the "Sort by" selection, could we possibly sort it as well? As the list of fields gets longer, it gets more difficult to find what you're looking for with them in (seemingly) random order.
Ideally, it would be nice if it could show only the fields that are actually available on the content type (or types) that have been selected, but I realize that would require it to be JS/AJAXified or changed to use a multi-form approach.
Comment #16
blanca.esqueda commented@ExTexan
Even if the Sort By selection list is filtered by the content type(s) selected. it won't resolve the issue you submitted.
Shared fields are displayed only once, so only one label can be displayed because those shared fields use the same field name. Title field is in this situation, all content types have a title field name.
Entity Reference field allows to select one or more bundles (content types, ..), so even when the Sort By selection list gets filtered by the bundle(s) selected the title label situation would be the same. Because the title field is set by default for content types, I believe the label exception has to be done.
Sample: On your entity reference select two bundles (content types), still only title field would be display with the random overridden label.
Filtering the Sort By selection list for sure would be good, but I think this can be handle as a different task.
Comment #19
extexan commentedIs there any way to find a solution for this? I understand @Blanca's point about shared fields, but perhaps we need to be showing the machine name instead of the first label found for a shared field. That would at least make it less confusing.
In a recent project, I have a couple of content types where I've overridden the title label. For example, one is "Customer". So when I want to sort a completely different reference field on "title", am I supposed to select "Customer" and hope that it will actually be sorted on the correct field? At least if I saw "title" - or, if I'm wanting to sort on a custom field, I'd see something like "field_purchase_order" - I'd know I'm choosing the correct field.
Comment #22
mpp commentedThe patch in #12 no longer applies.
Comment #23
mpp commentedComment #26
guillaumeduveauI have the same problem on Drupal 8.6.16 but on 8.7.9 it seems to have been fixed.
Could someone confirm ?
Comment #27
guillaumeduveauIn fact I still have the problem on Drupal 8.7.10. The sort order is correct when the referenced entity is not translatable or is translatable and has no translation.
As soon as 1 translation is added, it seems that this 1st translation takes precedence for the order. Adding a new translation does not change the order again.
Comment #33
quietone commentedThis still happens on Drupal 9.4.x.
This needs an issue summary update, see Write an issue summary for an existing issue for guidance. Updating the issue summary on this issue is suitable for a first time issue, adding novice tag.
Comment #36
quietone commentedThe is not currently a novice level task.