Follow up for #1801304: Add Entity reference field
Problem/Motivation
In views, it's Filter criteria, then Sort criteria.
In the new add entity reference, it's the opposite.
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.
Comment | File | Size | Author |
---|---|---|---|
#6 | target.png | 227.38 KB | YesCT |
#6 | content.png | 53.59 KB | YesCT |
#5 | Entity_reference_settings_order-1904882-5.patch | 1.02 KB | balsama |
#3 | Entity_reference_settings_order-1904882-3.patch | 1.09 KB | balsama |
views-order-2013-01-31_1706.png | 60.29 KB | YesCT |
Comments
Comment #1
swentel CreditAttribution: swentel commentedMoving to right component - unless I'm missing something.
Comment #2
YesCT CreditAttribution: YesCT commentedComment #3
balsamaThis 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.
Comment #4
mgiffordNote 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.
Comment #5
balsamaUpdated patch - removes extra line.
Comment #6
YesCT CreditAttribution: YesCT commentedNote: 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.
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
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
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.
Comment #7
webchickNice little improvement, thanks!
Committed and pushed to 8.x. (without the default.settings.php hunk, since that looked like an accident)
Comment #9
k0teg CreditAttribution: k0teg commentedIn comment #6
I have checked those issues and I can't reproduce the errors.
So no follow up issues are necessary.
Comment #10
rteijeiro CreditAttribution: rteijeiro commentedI can reproduce the error mentioned in #6 for "Contact message":
Cannot reproduce the error mentioned for "File".