Problem/Motivation

My entityreference field shows users with particular roles; they're ordered by UID by default. I sort them by "User: Name" for better UX. It stops working after updating from 7.x-1.5 to 7.x-1.8, defaulting back to the UID default sort.

Steps to reproduce

  1. Create an entityreference view of users; filter only users with a particular role; do not add any sort criteria yet.
  2. Add a new Entity Reference field with Select List widget to a content type. Under Entity Selection, reference the view above.
  3. Create a new node of the above content type, notice the Entity Reference field users are sorted by UID as expected.
  4. Edit the source entityreference view, adding Sort Criteria > User: Name (sort ascending). You should see the user names presented in alphabetical order in the preview below. Save the view.
  5. Flush caches to be safe
  6. Create a new node of the above content type, notice the Entity Reference field user entities are still sorted by UID, which does not match the entityreference view.

Comments

nodecode created an issue. See original summary.

joseph.olstad’s picture

Hello, thanks for reporting, please test the available patch and report the version of PHP you're using and report success results.

The patch is here:

#3349989-6: Field reference do not use order (asc,desc) that done in views reference

joseph.olstad’s picture

I would like some more reviews of the fix before putting it in. Particularly testing results with PHP 8.2

jvogt’s picture

This is still an issue for me in 7.x-1.9 when the field is referencing User entities. Tested on both php 7.4 and 8.1. It ignores both "A field attached to this entity" and "A property of the base table of this entity."

joseph.olstad’s picture

@jvogt what does this say?

drush pml | grep entityreference -i

jvogt’s picture

Well, I downgraded back to 7.x-1.6, but after running drush dl entityreference, the output of drush pml | grep entityreference -i is:

 Fields                           Entity Reference (entityreference)                                    Module  Enabled        7.x-1.9
 Fields                           Entity Reference Behavior Example (entityreference_behavior_example)  Module  Not installed  7.x-1.9