Follow up for #1801304: Add Entity reference field

Problem/Motivation

In views, it's Filter criteria, then Sort criteria.
views-order-2013-01-31_1706.png

In the new add entity reference, it's the opposite.
reference-order-2013-01-31_1704.png

It was confusing looking under the sort for "role" and took a while to notice that it was sort, not filter!

Proposed resolution

Put filter first, then Sort by. Make consistant.

Remaining tasks

TBD

User interface changes

Reorder something in the UI to be more consistant, no other UI changes or new patterns.

API changes

No API changes.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

swentel’s picture

Component: field system » entity_reference.module

Moving to right component - unless I'm missing something.

YesCT’s picture

Issue tags: +Novice
balsama’s picture

Status: Active » Needs review
FileSize
1.09 KB

This order is actually determined by the referenced entity.

The "Sort By" select list is generated in /core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/entity_reference/selection/SelectionBase.php

and the "Filter By" select list in /core/modules/user/lib/Drupal/user/Plugin/entity_reference/selection/UserSelection.php

The first line of public static function settingsForm(&$field, &$instance) is:

$form = parent::settingsForm($field, $instance);

If we remove that and add the following at the end of the function, this will reverse the "Filter by" and "Sort by" lists - but only for Users:

$form += parent::settingsForm($field, $instance);

I've attached a patch that does just that, but I suspect the issue will be bigger if we want to make it consistent across all referenced entities.

mgifford’s picture

Note that there's an extra line in the patch that shouldn't be there. Not a big deal but something to be cleaned up.

Patch applies nicely in SimplyTest.me.

balsama’s picture

Updated patch - removes extra line.

YesCT’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
53.59 KB
227.38 KB

Note: I had to remember to enable the entity reference module (of course)
And the place to change what gets referenced is in the target type in the field settings.

target.png

and the field settings (the edit tab on the field) admin/structure/types/manage/article/fields/field_ref

shows the order filter then sort as confirmed by @mgifford

what others have a filter by?
1. comment does not have filter by

2. contact message gives me an error (so an issue needs to be opened)
"Error message

Notice: Undefined index: schema_fields_sql in Drupal\entity_reference\Plugin\entity_reference\selection\SelectionBase::settingsForm() (line 115 of core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/entity_reference/selection/SelectionBase.php).
Drupal\Core\Entity\Query\QueryException: No base table, invalid query. in Drupal\field_sql_storage\Entity\Query->prepare() (line 121 of /home/sdea3727dc956a5e/www/core/modules/field_sql_storage/lib/Drupal/field_sql_storage/Entity/Query.php).
The website has encountered an error. Please try again later."

3. custom block does not have filter by

4. file gives an error (another issue)
"Fatal error: Call to a member function execute() on a non-object in /home/sdea3727dc956a5e/www/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/entity_reference/selection/SelectionBase.php on line 174"

5. menu link does not have filter by

6. content has checkboxes to filter, and they come first before sort

content.png

7. taxonomy term

is similar to the content (has checkboxes to filter by vocabulary above the sort)

8. user .. that is what we tested. :)

----
@balsama in #3

but I suspect the issue will be bigger if we want to make it consistent across all referenced entities.

So I dont think there is anything to do to make it consistant across all type of entities

------
the errors for contact message and files happen even without the patch. so rtbc from me.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Nice little improvement, thanks!

Committed and pushed to 8.x. (without the default.settings.php hunk, since that looked like an accident)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

k0teg’s picture

In comment #6
I have checked those issues and I can't reproduce the errors.
So no follow up issues are necessary.

rteijeiro’s picture

Issue tags: +Needs followup

I can reproduce the error mentioned in #6 for "Contact message":

Notice: Undefined index: base_table in Drupal\entity_reference\Plugin\field\field_type\ConfigurableEntityReferenceItem::schema() (line 74 of core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/field_type/ConfigurableEntityReferenceItem.php).
Notice: Undefined index: id in Drupal\entity_reference\Plugin\field\field_type\ConfigurableEntityReferenceItem::schema() (line 77 of core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/field_type/ConfigurableEntityReferenceItem.php).

Cannot reproduce the error mentioned for "File".