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

Issue fork drupal-2575259

Command icon 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

ExTexan created an issue. See original summary.

mikeker’s picture

Status: Active » Postponed (maintainer needs more info)

Can you give steps to reproduce?

mikeker’s picture

For 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.

extexan’s picture

@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.

extexan’s picture

I'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.

cilefen’s picture

Hi @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.

blanca.esqueda’s picture

@ExTexan

Hi, I followed your steps:

  1. Create Content Type 'Country'
    • Update title field label to 'Country', instead of the default 'Title' label.
  2. Create Content Type 'City'
    • Update title field label to 'City', instead of the default 'Title' label.
    • Insert an Entity Reference field pointing to 'Country' Content type
  3. Create Content Type 'Destination'
    • Insert an Entity Reference field pointing to 'City' Content type

And I think you are getting confuse.

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.

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.

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.

'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.

extexan’s picture

StatusFileSize
new21.21 KB

Ahh, 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).

blanca.esqueda’s picture

@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.

extexan’s picture

Yes, 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.

mikeker’s picture

Priority: Major » Normal
Status: Postponed (maintainer needs more info) » Active
Issue tags: -Needs steps to reproduce +Needs issue summary update

OK, 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!

blanca.esqueda’s picture

Issue summary: View changes
Status: Active » Needs review
Issue tags: -Needs issue summary update
StatusFileSize
new1.44 KB

In 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.

blanca.esqueda’s picture

Issue summary: View changes
blanca.esqueda’s picture

Issue summary: View changes
extexan’s picture

While 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.

blanca.esqueda’s picture

@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.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

extexan’s picture

Is 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.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mpp’s picture

Assigned: Unassigned » mpp
Status: Needs review » Needs work

The patch in #12 no longer applies.

mpp’s picture

Assigned: mpp » Unassigned

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

guillaumeduveau’s picture

I have the same problem on Drupal 8.6.16 but on 8.7.9 it seems to have been fixed.

Could someone confirm ?

guillaumeduveau’s picture

Version: 8.6.x-dev » 8.7.x-dev
Status: Needs work » Active

In 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.

Version: 8.7.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Branches prior to 8.8.x are not supported, and Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

mstrelan made their first commit to this issue’s fork.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

This 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.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Issue summary: View changes
Issue tags: -Novice

The is not currently a novice level task.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.