Continuation of #2429699: Add Views EntityReference filter to be available for all entity reference fields since there were so many comments the page was struggling to load.
Slack thread
https://drupal.slack.com/archives/C6SQM2J94/p1706633005193429
Problem/Motivation
One major piece of functionality from the D7 Entity Reference module was left out entirely in #1801304: Add Entity reference field: the ability to render exposed views filters as a select list or autocomplete of available entities.
Proposed resolution
Create a new Views Entity Reference filter plugin to be available for all entity reference fields but do not activate it at this stage. Make it available as an opt-in via views data alter.
How to use
- Add on an entity type / bundle an entity reference field, ex field_test_reference.
- Use views data alter to allow your field to make use of the reference (see code snippet below)
- Create a view displaying this entity type.
- Add a filter on the view for field_test_reference.
- Configure the entity selection mode and the widget display mode.
- Configure the filter behavior (ex: required, multiple, etc.)
- Finally use the filter field for filtering the results based on the selected entity from the autocomplete or select list.
Code snippet to use this filter:
/**
* Implements hook_views_data_alter().
*/
function MODULE_NAME_views_data_alter(array &$data) {
// Use entity reference for the field 'field_test_target'.
$field_name = 'field_test_field';
$data['node__' . $field_name][$field_name . '_target_id']['filter']['id'] = 'entity_reference';
}
Or use the contrib module: https://www.drupal.org/project/views_core_entity_reference
Remaining tasks
- ☑ support for content entity reference
- ☑ support for configuration entity reference
- ☑ support for content with and without bundles
☑ taxonomy filter rebased on generic entity reference- ☑ settings forms to configure the filter
- ☑ display widget in select or autocomplete
- ☑ filter values based on reference view
- ☑ filter values based on bundles
☑ maximum filter values in select list for performance concerns- ☑ sort for filter values when in bundle selection handler mode
- ☑ argument support for when view selection handler is used
- ☑ views configuration schema update
☐ existing configuration migration (no longer needed if we create a new filter only)☐ fix select option (#208, #215)- ☑ tests for general functionality
- ☑ write change record
- ☑ get framework manager approval
- ☑ update change record screenshots once green light has been given for this updated direction and considered ready to merge
Issues suggested to leave
As noted in #163, #164, and #169, suggesting we leave the outstanding non-checked items from below. Checked items are handled.
☐ Address points in comment #49 (comment 534 from original ticket)- ☑ add test coverage for calculate dependencies
☐ sort by empty on initial load (needs more info), see comment #49Unable to reproduce, perhaps tied to older version of patch☐ prevent circular reference: validate no selection of an entity reference that uses itself as the filter, see comment #49Suggested to be a follow-up- ☑ node titles in the select options when configuring the filter are double escaped (e.g.
"shows as"), see comment #49 - Resolved in #200 - ☑ exposed filters on the chosen entity reference view are also shown on the view, see comment #49 - Resolved in #199
Post tasks
- ☐ #3458099: Views handler loading should respect configuration : have views handler respect configuration to make it easier for filters to opt in
- ☐ After that lands, provide an UI to allow selection of which filter handler to use #3438054: Configurable views filters to allow for different widgets
- ☐ follow-up task for
TaxonomyIndexTid
#3339738: Convert TaxonomyIndexTid to use new EntityReference filter
- ☐ extract selection handler form logic in separate plugins that will specialize for rendering and validating the filter selection config form
- ☐ caching of the value form?
- ☐ documentation updates
- ☑ tests support for base fields
- ☑ #3458102: Add Views EntityReference filter to be available for all entity reference base fields support for base fields + tests support for base fields
User interface


|
|
Known issues
- CANNOT REPRODUCE ATM
sometimes when switching between widget it gets stuck on the previous selected one - FIXED
when switching between the widget types the previous value is left in the exposed form and it's incompatible with the other widget type - FIXED
triggering ajax requests on the extra options form right after adding the filter brings you back to the add handler formfixed
API changes
None.
For 10.2
See hidden branches and comment #143
| Comment | File | Size | Author |
|---|---|---|---|
| #213 | 3347343-213.patch | 80.05 KB | jsutta |
| #206 | Screenshot from 2024-06-28 12-32-23.png | 54.59 KB | acbramley |
Issue fork drupal-3347343
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:
- 3347343-10-3-x--comment-214-onwards--do-not-merge
changes, plain diff MR !9036
- 3347343-10-3-x--do-not-merge
changes, plain diff MR !8428
- 3347343-10-2-x--do-not-merge
changes, plain diff MR !6464
- 3347343-11-x
changes, plain diff MR !4053
- 3347343-continuation-add-views
changes, plain diff MR !3629
- 11.x
compare
- 3347343-10-4-x-backport
changes, plain diff MR !9226
- 10.4.x
compare
- 10.1.x
compare
- 10.3.x
compare
- 3347343-10-x
compare
- 10.2.x
compare
Comments
Comment #49
smustgrave commentedMoving over credit. Last comment from @Lendude that need to be addressed
@catch asked me to look at this again, mostly the test coverage. The test coverage seems mostly good, but ran into some other issues.
calculateDependencies is untested and should be since this is different than the Term plugin
The 'sort by' field is empty on initial adding of the filter (the field widget does something ajaxy when selecting bundles, the views widget does not, might be it?)
Grouped autocomplete filters don't work/save (but don't work for taxonomy ref filters either), please find the related issue or open it (should be one I think)
Description "as a Reference filter" feels a bit vague, did we get UX feedback on this?
Should we add this new filter for taxonomy terms too, or should we skip those since it is unclear what the difference is now when have to chose between the two different filters
I can create a circular reference by creating an Entity reference View that uses itself as the filter, not sure what goes wrong (mostly getting an empty filter after saving), but that sounds iffy
Maybe related : Managed to click my way into "Warning: Undefined array key "reference_views" in Drupal\views\Plugin\views\filter\EntityReference->submitExtraOptionsForm() (line 440 of /app/drupal/core/modules/views/src/Plugin/views/filter/EntityReference.php)"
Node titles in the select element are double escaped
Exposed filters on the chosen entity reference view are also shown on the view
Comment #51
smustgrave commentedCopied over MR from original issue to here.
Link to original MR https://git.drupalcode.org/project/drupal/-/merge_requests/3086#note_150528
Comment #52
smustgrave commentedTag from original issue.
Comment #53
alison(fixing comment number in issue summary)
Sidenote: I recommend editing #49 to get those list bullets back in, for readability.
Comment #54
dieterholvoet commentedI found another issue when trying to use the new
entity_referencefilter on a user reference field.Steps to reproduce
1. Enable the
entity_referencefilter for the node uid field2. Add the Author filter (category Node) to a node view, changing Selection type to Select list.
3. Open the view. The dropdown has no options.
The reason this happens is because
target_bundlesis set to an empty array. The reasontarget_bundlesis set to an empty array is becausevalidateExtraOptionsFormfailed, namely the following line:And that fails because
SubformState::getValuesfails:$this->getParents('#parents')returns['reference_default:user']and the array returned byparent::getValues()does not have areference_default:userkey, it does have anoptionskey. That's as far as I got while debugging.Comment #55
jonmcl commented@DieterHolvoet: I just happened to bump up against a similar situation. In my case it's a custom entity type that has no bundles.
I think the issue is actually in DefaultSelection, which I do not think is being touched by this patch. I suspect that only users of this patch would be trying to use DefaultSelection with a bundle-less entity, so maybe that is why it hasn't been an issue before? I'm not entirely sure.
In DefaultSelection::buildEntityQuery, there is this snippet:
And in DefaultSelection::buildConfigurationForm, there is this condition:
So I think that
'#value' => []needs to become'#value' => null, but I am not entirely sure that is the best solution or what other impact that change would have elsewhere. Alternatively, EntityReference::buildExtraOptionsForm could be modified to set $sub_handler_settings['target_bundles'] to null if the entity type does have have bundles.As a workaround, I ended up writing a custom EntityReferenceSelection plugin that extends DefaultSelection and changes target_bundles to null, when the entity has no bundles, inside ::buildEntityQuery. A little messy, but gets the job done (for now).
------------------------------------------
Update: I think I found the defect. The changing of target_bundles to be null, instead of an empty array, happens in
DefaultSelection::validateConfigurationForm. This method is called by EntityReference::validateExtraOptionsForm, but I am not sure the structure of $form_state is compatible anymore.So possible solution is to check for the target_bundles empty array and set to NULL inside of
EntityReference::validateExtraOptionsForm?------------------------------------------
Update 2023-06-23: I'm reporting back that the merge request 4053 is now solving this issue.
Comment #56
aaronbaumanEvery instance of
self::WIDGET_SELECT_LIMITandself::ALL_VALUEshould bestatic::.The use of
selfprevents any extending classes from overriding these uses, for example via replacing the filter class via hook_views_plugins_filter_alter().The use of
staticaccommodates this use.Comment #57
jonmcl commentedPer my update in #55, I think something like this is needed in
EntityReference::validateExtraOptionsForm. This will be to handle entities with no bundles and possibly for selecting no bundles on the subform.-----------
Update 2023-06-23: I'm reporting back that the merge request 4053 is now solving this issue.
Comment #61
smustgrave commentedGood to see this issue moving.again
Edit.
I started the 10.1 branch but now it needs to be 11.x
Can update the MR if that helps.
Comment #62
vasike@smustgrave please do ...
and thanks a lot
+ i just noticed something ... for drupal.org
i tried to select new people for credits (including you) ... but it didn''t update the commit message ... hmm
Comment #63
smustgrave commentedWas afraid of that. Think a new MR for 11.x will have to be started.
here's the MR before it got messed up.
Ignore the .gitignore file please.
Comment #64
smustgrave commented@vasike if you're working on this issue would recommend you start the branch so you have control of it.
Comment #65
vasike@smustgrave
it seems there is an issue with with 11.x ... and 11.0.x it doesn't seem "a real one" ...
so in ... a hurry ... we lost the track ... if i may say so .. :(
Comment #66
bramdriesenI had this issue as well somewhere else because the issue fork got created before the branch existed and is thus not in sync with all other branches. Let me see if I can fix it.
Comment #68
bramdriesenThere we go. If anyone is wondering how I usually fix this here is the process.
Comment #69
bramdriesenAlso @vasike
You don't have to include that in your commits. All commits will be squashed anyway when a maintainer commits this and sets the final commit message. Only maintainers of the module (or core in this case) can change the checkboxes.
Comment #70
smustgrave commentedI’ve been told issue must be committed to 11.x first and then backported. Didn’t mean to cause a road bump
Thanks for resolving!
Comment #71
vasike@BramDriesen very thank you
p.s. this is ... anyway ... witchery ... imho
Comment #72
bramdriesenNo problem, let's all be wizards 🧙♂️
Comment #73
vasikeUpdates on MR:
- rebased - using 11.x
- Fix for entities with no bundle -
DefaultSelectionNULL value - as User- Complete - Workaround for https://www.drupal.org/project/drupal/issues/2651418
to support sub-items (for Entities with some fieldset/tree options) - as User
- Use static for const, instead of self ... as suggested.
- Fix tests - remove duplicate (early check) + fix the check for Filter options.
Todo:
- Fix https://www.drupal.org/project/drupal/issues/2651418 - it will cleanup code in the MR.
- Entity with no bundle test - if really needed?!
Comment #75
bramdriesenUnrelated. Will hide that patch, not sure if that stops it from being retested or not.
Comment #76
smustgrave commentedTested out on 11.x standard profile
Added an entity reference field to the Article content type, pointing to basic pages
Created a Test view
Added the entity reference filter
Configured and verified it filtered correctly.
One part that was odd to me, won't hold it up, but when adding the filter it let me select the content types to filter by vs using the field settings.
But did notice a bug
I had 2 Articles, 1 with an entity reference value and 1 without
When I use the filter it shows duplicates of the 1 article with a reference. Imagine it would show any number of duplicates based on number of articles.
Comment #77
vasike@smustgrave
The "Reference selector" it's not a "field setting" ... but a "field instance setting"
Which means a field could be used with different "Reference type" ... on different bundles.
And i think it was discussed and "decided" in the original issue.
I can't replicate this. Are there other "elements" in your install? Maybe multilingual or something?
Comment #78
vasike@smustgrave checked again on duplicates
the only scenario is when we have multiple valued reference field and also multiple values selected for the filter.
Which is "normal" ... and with Aggregation we could get rid of duplicates.
So i can't see / replicate the bug.
Let's try NR ... so maybe there will find out is close to RTBC or ... not.
Comment #79
vasikesmall update -
FilterEntityReferenceTestfor kernel file and class name ... as it's about the filter ... not field.Comment #80
smustgrave commentedTagging for subsystem maintainer as it seems this feature will require aggregation now.
Comment #81
vasike@smustgrave
This is usual ... the "same results" you'll get also for a List field with multiple values and filter options selected ...
So it's not about this filter in particular ... but filter multiple values for multiple valued field ...
just saying
Comment #82
smustgrave commentedTested this again
Create a simple view of the Article content type with a filter for reference filter.
The filter is exposed and I see it in the preview.
The dropdown looks correct
But when I save the page and check the view page the filter does not appear.
Comment #83
vasike@smustgrave do you mean no filter at all?
No select input?
Or no select options.
This sound critical ... but could you, please, detail ... maybe screenshots for some steps?
Thanks
Comment #84
smustgrave commentedActually not sure what I did wrong. Retested again and the filter appears now.
Think this is good for committer review.
Also not seeing the duplicates, didn't need aggregation.
Comment #86
dieterholvoet commentedIn #2429699 comment #449, @Berdir answered the following when someone asked if the patch supports fields which reference configuration entities:
That doesn't seem to be the case though. If I replace
if ($target_entity_type instanceof ContentEntityTypeInterface) {withif ($target_entity_type instanceof EntityTypeInterface) {incore_field_views_data, it seems to work. My use case: I have an entity reference field on a node type, referencing webforms (a config entity type). After applying the patch and the change I just mentioned, I can add an entity reference filter listing all webforms, without issues.Should we change this so it also works with config entities? I don't see why not.
Comment #87
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #88
israelshmueli commentedThis problem also exists in Drupal 9.
I created a patch against 9.5.x based on 2 files from Drupal 11 commits in gitlab
1 new file added: core/modules/views/src/Plugin/views/filter/EntityReference.php
and 1 changed: core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php
This patch allowed me to get working exposed filter out of entity reference field that references content (nodes).
The probleme does not exist when the field references taxonomy terms.
The views filter should be of type "field_name as a Reference filter"
Comment #89
vasikeUpdates on MR:
- Fix the CSpell Failures
- And update to Do not limit filters available to Content Entities, use EntityTypeInterface ... as mentioned on #86
But separate filter from relationships condition, as indeed they are not "compatible".
In this way also we have aligned the filter available and Views Filter (
getReferencedEntityType(): EntityTypeInterface)let's try some review.
Comment #90
smustgrave commentedTried this out on a site we are developing.
The reference fields appeared correctly as Reference filters
Rendered as expected
Filtering is working perfectly.
Fingers crossed to getting in for 10.2
Comment #91
bramdriesenThe to-do list in the summary could use an update as well. 🙂
Comment #92
recrit commentedattached a static patch for builds. This represents the MR 4053 at commit 1bc7bda7.
Comment #93
catchIf we're adding support for config entities here, then we need the equivalent test coverage to confirm it works, so marking needs work and 'needs tests' for that. Another option would be to move that change to a follow-up, although the test coverage shouldn't be too bad to add.
Haven't done an in-depth review of the rest of the patch yet, just noticed this but added a couple of additional points from a quick look.
Comment #94
amateescu commentedThis change is not correct, a
NULLvalue for thetarget_bundlessetting means "all bundles are referenceable", while an empty array (the current value in HEAD) means "no bundles are referenceable", so this is a behavior change in the default selection plugin...Comment #95
recrit commented@amateescu I agree the change seems odd since it will affect all entity selection handlers.
Here's an audit for the change to "core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php":
Comment #96
vasikeabout the change
This is needed in order to get the "bundless" entities - to work.
Without it. there are no "options" for the Referenced entities.
So the question, do we still need to keep this and make it work for entities without bundles.
or this change "won't" harm.
Comment #97
vasikeUpdated the MR with some tests for Filter of Config Entities References.
The. node type config was used for Entity Reference Testing Field.
Comment #98
smustgrave commentedAgree with #91 if the issue summary bullets could be looked at.
Comment #99
smustgrave commentedJust for issue summary and tags update/cleanup.
Comment #100
vasikeUpdates:
- Updated summary
- Change record draft available
- Remove tags: Needs issue summary update, Needs tests
- Add related issue, as the MR code contains this issue reference https://www.drupal.org/project/drupal/issues/2651418
Comment #101
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #103
vasikeComment #104
smustgrave commentedAppear to have 2 open threads from @catch that need to be addressed.
Thanks
Comment #105
sthomen commentedI'm not sure if I've missed something obvious, but this change seems to cause views to pull in the refercenced entity with an inner join. This does not happen with the default NumericFilter where it becomes a left join. I had a cursory look at the code but couldn't find out where/why this happens, but perhaps someone more versed in views can have a look.Nevermind, I am creating a module that can copy the input value from another field to allow me to check two referenced fields with one exposed input, and am probably doing it wrong.
Comment #106
vasikeThere was an attempt to cleanup the code about required "fields" for the selection handler options
https://git.drupalcode.org/project/drupal/-/merge_requests/4053/diffs?co...
And it "works" in the UI without issues.
But it seems the tests fails.
Something it's broken in the Views/Modal forms validations - or at least for required fields/elements.
And the extra code (
setRequiredViaStatesOnChildren) helps for tests to pass.Unfortunately ... there is no "FunctionalJavascript" tests on Filters with extra options (
buildExtraOptionsForm)or at least i couldn't see such tests.
That could help us here ... i'm also not aware on the other core issues related with those things.
So for now i just reverted the change to previous "state".
I still think the code could be cleaned up for both Filter plugin and its test.
Questions:
TaxonomyIndexTid / TaxonomyIndexTidDepthplugin filters do not have "FunctionalJavascript" tests, only "Functional" testsCould we consider the same here. So maybe we don't need the "extra code" for this new filter?
@sthomen do you mean this change mentioned. could you please check again? as the change was reverted.
thanks
Comment #107
sthomen commented@vasike My apologies, I was just being dumb. Please ignore my comment.
Comment #108
vasikeThere is a second attempt to clean up the MR code on both Views Filter plugin and its tests.
For Views Filter plugin the cleanup also tries to address/solve the 2 open threads
1. A todo about conditional required - removed the code, i think this "todo" will have small chances to be chased and solved soon
And, for now, it's not used (needed)
Also renamed the method for this
setRequiredViaStatesOnChildren->removeRequiredOfSubformChildrens2. A "todo" about the extra options form validation. It seems the original issue has a related issue linked ... which it was missed when this new one was created
https://www.drupal.org/project/drupal/issues/3163740
So i cleaned up the code there and added the related issue url.
3. Re-arrange some code - to be easier to maintain/read
For tests code
I tried to cleanup - use similar code with existing code on filters ... with the same goal - - to be easier to maintain/read (toghteter with other related tests).
i hope we got closer to an end here
Comment #109
vasikeforgot to link the related issue
Comment #110
catchI needed this on a client site, and noticed that the entity reference filter doesn't show up for base fields.
This is easily solved with the following additional change:
However, changing the filter type (as opposed to adding an extra field in the views data), is not compatible with the current approach taken here.
I am wondering why the approach was changed to add an extra field, it adds a lot of noise to the UI when the 99.99% use case will be to use this filter anyway. I don't see how this can be applied to base fields without either changing the approach, or refactoring EntityViewsData to allow field types to produce multiple fields, or hard coding this reference type in there somewhere.
Also added a couple of review points to the MR.
Apart from those issues, this looks close and it would be great to close it before this continuation issue is as long as the original.
Comment #111
scott_euser commentedThat happened way back here after chatting with lendude at Drupal Dev Days.
https://www.drupal.org/project/drupal/issues/2429699#comment-14472189
If I remember correctly, without this MR you can set up the reference field to eg find all node IDs >= 1000, but switching to an entity reference you lose the more math related options like that. While it seems like edge case, it is possible users are using the filter as is to do such things. So a separate filter seemed the only way to not break existing sites.
Comment #112
vasikeSome thoughts about the change https://git.drupalcode.org/project/drupal/-/merge_requests/4053/diffs?co...
Why, imho,
NULLvalue will not harm at all (there).1. It's a form value element for entities that doesn't have a bundle key
2. defaultConfiguration has
NULLvalue3. The field settings will save actually
NULLvalue for entities without bundle@see validateConfigurationFormResult
4. And of course the "docs" about
NULLvs[]"results"So my conclusions are:
1. The Change to
NULLshould not break anything2.
DefaultSelectioncould be improved for "bundless" entities3. Subforms and validations not working "great" on Views Filters.
@catch what do think?
thanks
Comment #113
vasikeMR updated ... trying new approach to make it work for entities with no bundle.
As part of the conclusions from #112, about
DefaultSelectionI noticed that the configuration form validation "imagines" that we have a field settings form.
Which means the validations there won't work in another forms.
So i moved the validations from form validation to elements validations - for portability.
And it should work.
p.s. i still "believe" in things i shared on #112
Unfortunately ... the MR started failing ... PHPStan ... and the last one looks odd ....
If there's anyone that could help with this error?
thank you
Comment #114
smustgrave commentedThat's a tough one, applied locally and even phpstorm isn't picking up on that. Usually phpstorm is good with those kind of pickups.
Comment #115
vasikeFixed the PHPStan errors.
However now we have the "CSpell" CI issue ...
https://www.drupal.org/project/drupal/issues/3401988
Comment #116
damienmckennaRe #111, could this be handled as a backwards compatibility break in a major release? Alternatively, I wonder about creating a small contrib module to switch the definition..
Comment #117
vasike@DamienMcKenna with all my respect, I would say that, this is "out of box" issue.
2 things
- Views is in Core
- EntityReference is in core
What's not in core ... is Views and EntityReference "real integration"
This is just a small part to involve more people to help with Views ... is far from "core" ... yet ... imho
But thanks for your thoughts.
Comment #118
damienmckenna@vasike: Apologies that I wasn't clear, I was talking about to the suggestion in #110 to simply change core's field specification to use "entity_reference" instead of "numeric"; could this change be introduced as a breaking change, maybe with documentation on how to use the field as a number?
Comment #119
smustgrave commentedWith regards to #3401988: Spell-checking job fails with "Argument list too long" when too many files are changed there is a work around posted to the ticket but I'm not super clear how to best do it.
Comment #120
scott_euser commentedRe #111 / #116 perhaps best is to:
Then in follow-up (because all the below is a lot of work in itself and big scope increase):
If that's at all possible / interesting perhaps that discussion can be had in a postponed issue to avoid this issue growing too big again
Comment #122
fjgarlin commentedThis issue was hit by the issue mentioned in #119, but also the fact that the branch 11.x wasn't even present in the fork (I think this is another core issue).
I brought 11.x to the fork and the MR should now run. I have no more context on the issue so not sure if it should be back to "Needs review" or still "Needs work".
Comment #123
vasikeComment #124
smustgrave commented@catch
What are you seeing that appears broken exactly?
Comment #125
catch@smustgrave I mean that if you expose an entity reference filter in HEAD, then you get an empty text field with no indication of what to put in it, which to me looks broken and I doubt people are using it much as-is. Given that, I think we should consider applying the new behaviour to the existing filter, not adding a separate one alongside. This would also help with applying it to base fields, which the MR currently does not.
Comment #126
berdirThere are ways to use it and I've done it before. For example in combination with grouped filters, which obviously doesn't scale, but is a decent workaround when you have for example a config entity reference with only a handful options.
Comment #127
scott_euser commentedRe #125 you could be using the filter without exposing it though, eg all node IDs >= 1000. Ie, not useful for a visitor but possibly useful for a site builder?
As per my response in #111 that's why chats with @lendude suggested that would be the most realistic way to get this in core.
I would also prefer to not have the extra filters in an ideal world and replace instead if you think we can get away with just a change record but I am concerned this then never gets in as many of us have spent chunks of time on this over the years and the goal-posts changing makes it tough of course.
Would you be the one signing off on this eventually or should we seek review from a different core committer as well?
Asking first because, if we go through route, it's probably a fair amount of work to change the MR but also then possibly further extend the MR to need update hooks (and upgrade tests?). So I think we should probably agree scope and ensure agreed scope has a realistic path to actually making it in before actioning a change of approach... Or agree to keep the current scope
Comment #128
smustgrave commentedWould love if this doesn't get re-scoped at this point of it. If it could be improved in follow ups +1 for that.
Comment #129
catch@scott_euser I'll try to get a second and if possible third or more opinion from other core committers so this doesn't get turned around again.
@Berdir same question as #127 - is that exposed to site visitors, or exposed at all?
Comment #130
vasikeI open a "thread" on slack
https://drupal.slack.com/archives/C6SQM2J94/p1706633005193429
Also added to summary
And I'm wondering if it's not more efficient for discussions than to "fill-up" issue comments
p.s. maybe it could be a way for drupal.org to have a slack url about discussion on some issues.
just thinking aloud
sorry for the noise.
p.s.2 and i'm trying to silent (here)
Comment #131
scott_euser commentedUpdated issue summary to reflect need to add support for base fields into this as per message from @catch in Slack.
Also moving back to Needs Work since there are other items in the list that are not yet completed as well.
Comment #132
scott_euser commentedSupport for base fields added, but needs tests (updated issue summary).
A good example is 'uid' field in default Files view, so an easy way to try this locally:
Comment #133
vasikeComment #134
scott_euser commentedProblem at the moment is HandlerAllTest::testHandlers() fails on Comment 'Parent ID' base field, its getting allowed to use the new 'entity_reference' filter handler, but then something inside the new filter handler does not like that as a target. I ran out of time at the moment in case anyone wants to pick this up, otherwise I will try to pick it up myself again later.
I suspect sorting that issue will sort out the tests (unless there are further issues with supporting base field).
Comment #135
scott_euser commentedOkay tests passing now + new test added for base field reference.
So just comments from #49 left to address.
Comment #136
vasikeComment #137
deasly commentedI have this merge request running in a patch on my Drupal 10.1 site. It was running fine until recent updates made to it. Now Composer wont patch it into core using "cweagans/composer-patches". Am i the only one with this issue? What should I do to get this working again the way it was? "https://git.drupalcode.org/project/drupal/-/merge_requests/4053.patch" I'm probably not the only one.
Any thoughts on how to proceed would be appreciated as its currently blocking my monthly maintenance. Thanks.
Comment #138
scott_euser commentedHi @Deasly.
The merge request is meant to target Drupal 11 and it needs to continue to do so in order to eventually get in.
In the future, best to be downloading the patch file into your project and committing it, so you reference the local file, see here for details. It also talks about how you can do a git diff to make your own patch. The challenge here is you need to find the commit id of a version in the merge request that you are happy with then the commit ID eg of latest 11.x. Then its `git diff new-commit-id old-commit-id > patch-file-name-here.patch.
That only works if there is an older version that affects files that do not have a merge conflict with 10.2.x (the version I am guessing you are on). And of course you miss out on the additional stability/bug-fixing of the latest commits in the Merge Request.
Hope that helps!
Comment #143
scott_euser commentedSorry for the noise here, not sure an easier way to help others out that want to use this in 10.2.x as I realise its a challenge to resolve conflicts as soon as the 11.x MR starts to become incompatible with 10.2.x like it is.
I created a branch 3347343-10-2-x--do-not-merge which people should be able to use the diff from to create a local patch BUT please bear in mind the code is just cherry-picked from the Drupal 11 Merge Request code and its therefore very possible that code is referenced that only exists in Drupal 11 and does not exist in Drupal 10 which can lead to errors, so do use with caution.
Comment #144
scott_euser commentedRegarding #49 I have updated the issue summary with outstanding items. Details below:
Added tests mimicking the coverage that TaxonomyIndexTidFilterTest::testConfigDependency() provides.
I could not spot a 'sort by' when using a field widget on an entity reference field. Is it possible to provide further steps?
Here is the related issue I think #2576927: Grouped exposed taxonomy filter fails validation for autocomplete widget.
Perhaps this should be dealt with in the deprecation dance when the old filter gets removed. Added as a follow-up task.
We have this as a follow-up now #3339738: Convert TaxonomyIndexTid to use new EntityReference filter.
Needs work - added to issue summary as a task
Needs work (I can see this works in TaxonomyIndexTid, so its not a wider problem) - added to issue summary as a task
Needs work - added to issue summary as a task
Comment #148
smustgrave commentedJust to avoid any confusion I hid the other MRs but left a small note in the summary.
Tested out the latest changes
Standard Profile install
Added a content reference to the Article content type, using basic page as the target
Created a few basic page nodes
Created a few article referencing those basic pages
Updated the content view to use Content (field_content) as a Reference filter
I was able to setup as a dropdown no problem
Filters worked as expected
No errors in logs.
+1 RTBC from me but will leave in review for additional eyes.
Comment #149
vasikeNew commit to remove a "@todo" from code ... about ajax property on Entity Reference Selection plugin.
From related issue https://www.drupal.org/project/drupal/issues/2651418
please check the latest comments there.
Comment #150
seanrI'm a little confused by this thread (it's quite long and convoluted), but is there a patch/MR that works against D10? I've got a client yelping about this. :D
Comment #151
scott_euser commentedUnder the branches listed at the top, click to show hidden branches and see '3347343-10-2-x--do-not-merge' - is has a port of the 11x merge request for 10x sites.
Comment #152
smustgrave commentedFYI been using this for about a week on client side on our content view, have a dropdown for a taxonomy field and user reference field.
Comment #153
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #154
vasikeSolved conflicts and also new CS issues
However it seems there are other things going on for CI
As the new
Validatable configjob ... which, of course it failsProbably this should be covered by a child issue
https://www.drupal.org/project/drupal/issues/2869792
... which seems ... missing
"Not ideal ... to be polite"
I put the issue for Review ... just to gain some attention
As the feeling is that it could become stalled ... as original ... for other years.
p.s. also linked those issues ... maybe there we could have more awareness
Comment #156
elamanNot an input to the issue, just a patch for 10.2.x
Comment #157
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #158
vasikeMR green again
Also I hid the latest patch ...
needs-review-queue-botdoesn't like it https://www.drupal.org/files/issues/2024-03-14/3347343-nr-bot.txtComment #162
smustgrave commentedThanks everyone for keeping this one going.
Wonder if any of the remaining tasks can be scratched off? Maybe can start reaching out to the sub-maintainer and framework managers next week for sign off.
Comment #163
scott_euser commentedThese are the remaining tasks from the issue summary (other than getting framework manager approval):
To get this over the line, could we consider all of these back-end minor edge cases? None of them stop the site builder from achieving the primary task and none of them affect the front-end functionality for the visitor. So perhaps we could consider them as follow-ups? They would be easier to achieve in isolation later.
Comment #164
smustgrave commentedPersonally I think it would be nice to get this in now and improve in follow ups. If it's functional and covers most scenarios that is.
Comment #165
rodrigoaguileraFor folks that use patches, the patch from #156 doesn't apply to 10.2.5 so here is one without the phpstan-baseline changes that applies to both.
Comment #166
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #167
recrit commentedAttaching a static patch of MR 4053 for builds to use. This patch applies to 11.x and 10.2.5.
Comment #168
recrit commentedI had a custom selection plugin that extended
Drupal\views\Plugin\EntityReferenceSelection\ViewsSelection. Since the plugin ID was not "views", the detection to remove the element validation (unset($sub_handler_settings['view']['#element_validate']);would not run, resulting in silent form error and the filter config values not saving.I changed views handler detection to class based instead of plugin id to support any plugin that extends the ViewsSelection class.
Comment #169
acbramley commentedPlease stop uploading patches to this issue. It is causing problems with the NR bot and making this even more tedious to try and get over the line.
I completely agree with #164 - let's get this in and polish it further in follow ups if needed before we get to another 500 comment issue.
Comment #172
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #174
vasikeComment #176
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #177
catchComment #181
mortona2k commented@scotteuser - Hey I tried to update the 10.2 branch for 10.3 yesterday, but I couldn't figure out a good way to do it. First I tried to rebase, but gave up after a bunch of conflict resolutions. Then I tried merging, most of the important changes were merged no problem, and I tried to check for other relevant changes but it's a big list and hard to verify. When I completed the merge, it was about 80% right with some extra stuff.
Do you have any notes on how to do these kinds of branch updates in a sane way?
Comment #182
scott_euser commentedI definitely had a bit of hair-pulling as well, what I ultimately did was take the merge request diff as a patch and ran the apply patch via phpstorm which applied most files. Then I manually redid the views.views.inc as it could not manage that. So yeah, no sane way I could find yet either :)
Comment #183
scott_euser commentedI would have thought that https://git.drupalcode.org/project/drupal/-/merge_requests/4053/diffs?co... would fix this. Maybe I did the wrong thing, would appreciate if anyone has any tips. It seems there is a giant inheritdoc chain and this MR is just surfacing a deeper issue elsewhere.
Comment #187
kksandr commentedComment #190
webdrips commentedIt would be lovely to get a patch or MR that works with 10.3.0
@scott_euser can you create a patch based on what you did?
Comment #191
abx commentedFor 10.3, use 3347343-10-3-x--do-not-merge Copy link from plain diff ( You will get a patch link here -> https://git.drupalcode.org/project/drupal/-/merge_requests/8428.diff )
I patched it through composer and it patched cleanly.
Comment #192
acbramley commented@abx don't use MR
.diffURLs, that is opening your site up to security vulnerabilities since anyone can push to that branch (and then subsequently make changes to the module when your site installs the new patch).Instead you should download and store the diff locally.
Comment #193
abx commentedThank you acbramley. I will do that.
Comment #194
webdrips commented@acbramley that's very good to know, thanks! Should the community as a whole not go back to providing patch files on d.o in that case (at least until the issue is addressed)? It seems silly to make everyone go download the same file to me.
Looks like MR 8428 applies cleanly to 10.3.0, so thanks also to @abx.
Comment #196
acbramley commented@webdrips no, because it confuses the issues and makes things much harder to manage for reviewers and commiters. This issue is already extremely long in the tooth (almost at 200 comments and we've already had to recreate the issue because the last one had too many comments to load). Uploading patches will only cause more issues.
Comment #197
acbramley commentedBack to NR. We should probably squash all commits on the branch back to a single commit if this goes green too.
Comment #198
scott_euser commentedThanks for sorting out my poor merge! Apologies for that!
Yes here is the documentation for the merge request diff -> patch process which goes into more detail on the how & why.
Comment #199
scott_euser commentedA) Resolving "exposed filters on the chosen entity reference view are also shown on the view, see comment":
Confirmed: No child exposed filters from the entity reference view are shown any more.
B) I moved the circular reference comment to a follow-up as per earlier discussions (ie, the ability to select an entity reference that uses itself as the filter).
Comment #200
scott_euser commentedAlso resolving "node titles in the select options when configuring the filter are double escaped (e.g.
"shows as"), see comment #49"I added some special characters to the titles of my reference-able content including the " as noted and all appear fine within the exposed filter configuration.
So that leaves only "get framework manager approval" as the final issue to sort. If others agree, it would be good if someone can do a final check and RTBC this that was not so involved in the code (since its probably not appropriate for those of us that were involved in the code to RTBC it).
Comment #203
smustgrave commentedI don't mind marking as I haven't touched the code in some time. But I've been using a patch of this for some time without issue.
Comment #204
acbramley commentedSpoke to @catch in slack yesterday and going to pull on the thread of #110
This is to avoid having a new field.
Comment #206
acbramley commentedUnfortunately this is not the case.
After a lot of experimenting, I finally found a base field to test this properly on - you need a base field that's a content entity reference that's not the author (because that already uses another plugin). What I used was the Comment Parent ID.
Test steps:
1. Install standard profile
2. Edit the content view and add a relationship to the Comments field on the node
3. Add an exposed filter on Comment: Parent CID using the above relationship. This will be a numeric filter
4. Add some comments to a node and test that the filter works
5. Edit
EntityViewsData::processViewsDataForEntityReferenceand change$views_field['filter']['id'] = 'numeric';to$views_field['filter']['id'] = 'entity_reference';6. Clear cache
7. Test the filter works again.
You're presented with the following error:

Very surprised that the plugin is evaluated at runtime but so be it.
This is now a tricky situation, because I agree (after doing some more testing) that the current solution is not something we should commit. You currently get duplicate filters for every single entity reference filter. This includes fields like Authored By, which already have special filters (e.g for Authored by, it uses the user_name filter plugin)
But swapping out numeric filters may cause other issues for existing sites.
Not really sure where to go from here, so I think this needs to be Postponed until we come up with a viable solution.
Comment #207
scott_euser commentedMaybe we'll never get an upgrade path though because there are comparison options in numeric that just are not available in entity reference. This goes back to the slack thread https://drupal.slack.com/archives/C6SQM2J94/p1706799363236089?thread_ts=... and whole idea of avoiding a BC. Can we descope base fields so we continue to avoid BC and set they as a follow up issue? Ie, get back to a situation where it is truly opt-in for existing sites. What do you think? We could move back to slack to chat fundamental approach again.
Comment #208
scott_euser commentedI imagine most people are not using this for Comment Parent ID, and perhaps contrib can support any breaking change overrides if someone does want entity reference for cases like that, but as noted in #206 it is hard to find base fields that do not have an alternative to 'numeric' filter already provided by their respective modules in core.
So for now I reverted the support for base fields and will raise it back in the Slack thread where it was originally suggested that we should support the base fields. @catch's request for base fields was an 'ideally', but maybe given the potential problems it causes we can move that to a follow-up.
Comment #209
scott_euser commentedChatted with @catch and @acbramley in slack, I get it now: we can avoid an upgrade path if the View would respect the configuration. So existing configured filters using numeric would stay numeric, and new filters added would be configured as entity_reference therefore not needing an upgrade path. So in theory if we can get Views to respect the configuration (separate issue) then we can have an easier time here. If that does not seem doable, then we continue down the route of the alternative filter, leaving both options available.
One thing that does need work though is to try to reduce extra alternatives where another module in core already provides an alternative to the numeric filter. I started on that but needs work.
Comment #210
scott_euser commentedComment #211
scott_euser commentedPostponing for the pre-issue as per issue summary
Comment #212
acbramley commentedReset the branch back to before the experimentation for removing dupes.
Comment #213
jsutta commentedHello all,
I couldn't get the 10.3.x branch to apply, so I created a separate patch that applied in my local environment just now. This is just a band aid though, and I'm happy to investigate why the 10.3.x branch won't apply if needed.
Comment #214
catchComment #215
scott_euser commentedAs discussed in Slack here as suggested by @catch, the change to views data & views data alter has been reverted and the EntityReference filter is made available without being used, allowing it to be used in place, rather than with the 'as a Reference' duplicate filter.
The issue summary has been updated with a code snippet of how to use and a contrib module automatically opting into this will be provided assuming the direction is accepted and ready to merge. That contrib module could also be used to provide any upgrade path away from the 'as a Reference' in case any sites are making use of the patch.
Tests have been updated to match without any functional change to the tests other then to stop referring to the _reference/'as a Reference' aspect of the filter.
The issue summary has also been updated to match this change in general.
Finally, the change record has been updated, though could use someone to update the screenshots when this is ready to merge.
Comment #216
scott_euser commentedComment #217
scott_euser commentedComment #218
catchThis feels like it might unblock things. Short version of how we get to the original end result assuming everything currently being worked on comes together:
1. Add the new filter here, but not automatically to views data yet.
2. Do #3458099: Views handler loading should respect configuration so configuration is respected in views.
3. After #2, do #3438054: Configurable views filters to allow for different widgets to allow the filter plugin to be selected in the UI. This would be an extra UI element in views, plus some kind of API for plugins or fields to declare compatibility with each other tbd.
The for entity reference fields, there'd be a choice of numeric and entity reference, and site builders can choose which one, and we don't have an upgrade path or bc concern specific to the entity reference change - although there is still quite a lot of that in #2 and #3 overall.
Comment #219
scott_euser commentedThanks! Updated issue summary post tasks as per #218
Comment #220
catchReviewed the MR and it all looks good to me.
Retitling because the latest approach doesn't make it available for all entity reference fields yet, that bit will happen in #3438054: Configurable views filters to allow for different widgets.
Leaving the framework manager review and subsystem review tags because the latest approach was my idea and this issue has a lot of twists and turns.
Comment #221
jodavidson commentedHello all,
With all the twists and turns this issue has taken I wonder if there is a current solution to getting the Settings option back in place for exposed entity reference filters?
For 10.2.7 the patch here: https://www.drupal.org/files/issues/2021-12-02/2429699-453-9.3.x.patch worked well. In 10.3.1 I've made a local patch from MR !4053 mergeable (above) and applied it. Unfortunately it does not return the Settings option. Looking at the past few comments maybe it is not supposed to by itself?
Reading through these issue chains is pretty confusing for me, (and many others I imagine,) so I thought it best to ask for some clarification. Personally my site is frozen at 10.2.7 until there is a solution for this issue.
Thanks for your time and work on this issue, it sure looks like a big can of worms that has existed since D8.
Comment #222
mmenavas commentedMy site is also frozen at 10.2.7. Let us know how the community can help out.
Comment #223
scott_euser commentedHi @jodavidson,
Essentially the problem with making a separate reference field (the 'as a Reference' that existed in some versions of the patch) would be very hard to merge back later.
Then the problem of replacing all existing Entity Reference filters on place is that the current Numeric filter offers more options (like all node IDs > 100) that would be lost and therefore it'd be a breaking change.
So the current status is to provide the Entity Reference filter but not actually make use of it (some follow up tasks to allow a content editor to use it via the UI). Splitting into follow-ups means we can actually get it to land (hopefully) but making this scope significantly less risky.
There is a code snippet in the issue summary now that shows how to make use of the latest merge request, but assuming we get framework manager approval I'll create a module in contrib that effectively does that for now until the follow-ups land (on the framework manager approval @catch noted he wants other eyes to grant that since he's the one who came up with the idea of the above).
So tiny bit of limbo state as I don't want to go make that contrib module unless we are quite confident this will be the agreed direction.
Hope that helps clarify at least (I know it doesn't solve sorry!)
Comment #224
en-cc-org commentedOur site is also frozen at 10.2.7, but (not realizing patch #453 would work), I applied this patch https://www.drupal.org/files/issues/2024-04-17/3347343-comment156-10.2.x... As mentioned, this patch required me to rebuild my views to use the new "field_name as a reference filter". All is stable for now. Thankful to those continuing to find solutions as we are very dependent on this feature.
Comment #225
jodavidson commentedThanks @scott_euser.
If I understand the summary notes. I create a basically empty custom module that really only has the hook_views_data_alter() snippet in its MODULE.module file. And the patch should take effect once the custom module is activated?
Comment #226
scott_euser commentedCorrect if you are using latest merge request. The automated test coverage has to do the same thing in order to test the filter, so you can see that code here applying to all entity reference fields that are currently set to use string or numeric filters: https://git.drupalcode.org/project/drupal/-/merge_requests/4053/diffs#2f...
With such code applied (replacing with your own module name instead of that module which is named "views_test_entity_reference"), after clearing cache, adding a new filter with entity reference should show you the entity reference options rather than numeric options for example.
Comment #228
lendudeThe new approach makes sense to me too, follow up steps look good and make sense.
Left some minor nitpicks on the MR but this sounds like a great way to get something in without it being very disruptive.
Comment #229
scott_euser commentedThank you for the review!
I think we are ready then!
Comment #231
catchCommitted/pushed to 11.x, thanks!
Moving this back to 10.4.x to discuss whether we want to backport it there - I think it meets the criteria for a backport to the maintenance branch because it will allow contrib modules to use the new filter plugin in their views data definitions, as well as a potential contrib module applying the filter to core entity reference fields.
Comment #232
scott_euser commentedAmazing thank you! And thank you everyone for all the contributions to this over the years! I will set up a module now to make it easy for people to opt-in to this + migrate from older versions of this patch. Watch this space. I think we should also suggest to the contrib modules that offer similar functionality like VERF to suggest this Core plugin instead and move to minimally maintained. I don't know enough about the contrib modules to know if that is right though so good if the maintainers of those can feed back about them.
Would love it if this gets backported to 10.4 as it means we can take advantage of it sooner without patching. Given the final approach, does no harm I think, so just a policy question I guess?
Comment #233
scott_euser commentedModule created here: https://www.drupal.org/project/views_core_entity_reference
Feedback and contributions welcome!
Comment #234
andypostchange record needs update for versions
Comment #235
scott_euser commentedHow does that work: introduced in branch 11.x for now I guess, and leave version blank until there is a release? Or do we put 11.0.0 (and again change later if back ported)
Comment #236
andypostAs #231 said it needs backport to 10.4.x
Comment #237
scott_euser commentedOkay found the doc page for it https://www.drupal.org/community/contributor-guide/task/write-a-change-r...
If I got any of this wrong apologies!
Comment #240
scott_euser commentedIn case the decision is to backport I created branch 3347343-10-4-x-backport
The test failure is to core/tests/Drupal/Tests/Core/Command/QuickStartTest.php which passes fine locally, but does take a very long time. Seems very unrelated to this.
Comment #241
scott_euser commentedOkay backport tests pass @catch in case you want to backport. Thanks!
Comment #242
catchMoving to needs review. Still need to get a second opinion on backport since this would be the first bigger new thing to get backported to 10.4.
Comment #243
smustgrave commentedI'd be a +1 for including this in 10.4 if possible.
Goal is obviously to get to D11 but realistically maybe can make that jump in 11.1 when more contrib modules are updated. So will probably go to 10.4 before can go to D11 so having this functionality would be nice.
Comment #244
smustgrave commentedGoing to mark as think getting into 10.4 would be a very nice to have.
Comment #245
anybodyAnother +1 for getting this into 10.4.x! This is essential. Thank you all, great work!
Comment #246
vasikeI applied the 10.4 MR on 10.3 project ... but it doesn't seem to work - broken existing handler and no new filter available.
Sorry but I didn't have time to review the MR ... changing the status ... just to gain attention ... maybe I'm missing something
Comment #247
scott_euser commentedProbably on your 10.3 project you were using the 'as a Reference' filter version of the patch (ie, if your patch was over roughly a month old). Core won't have updates between patch versions but I did attempt to create an update in contrib, more details here: https://www.drupal.org/project/views_core_entity_reference
Comment #248
catchRestoring status
Comment #249
vasikeI checked again and it "works as designed" ... sorry about my previous noise.
@scott_euser Thanks for the support
Are we good to close this beast?
Comment #250
scott_euser commentedNo problem! Keeping it RTBC for backport to 10.4 decision essentially I think, but either way we get this in 11 at the latest.
Comment #251
damienmckennaI'm working on a site that uses a computedfield like so:
The ExpertsField class extends EntityReferenceFieldItemList, uses ComputedItemListTrait and then implements computeValue().
With the changes here, when I load the edit page for a view of a Search API index that has this field as an exposed field, it results in this error:
Is it possible that this functionality is incompatible with computed fields based on the entity_reference base field?
Comment #252
scott_euser commentedAre you opting in to the entity reference filter? Ive never used computed fields (that I know of), perhaps makes sense to raise a follow-up issue?
Comment #253
damienmckenna@scott_euser: No, I've only just applied the patch on a 10.3.2 site.
I'll open another issue and will reference it here.
Comment #254
damienmckennaI opened #3477391: computedfield vs entity_reference base field for the problem I've ran into.
Comment #257
anas_maw commentedCan you add the support for the entity none fields (properties)? like entity owner
Comment #258
catch@damienmckenna did you apply the MR diff or the patch? The patches here are extremely out of date with the current state of the MR.
Comment #259
anas_maw commented@catch I applied the MR #9226, and it's worked fine for fields, but not for entity properties.
Comment #260
anas_maw commentedThe property is showing as an auto-complete filter, but when you select and click apply it's not giving the right results.
I checked the query the where condition is not added at all
Comment #261
catch@anas_maw the MR doesn't change anything in views by itself, were you implementing custom code to add the filter to an entity property?
Comment #262
damienmckenna@catch: I believe it was the MR.
Comment #263
scott_euser commentedI did add a suggestion to your issue at #3477391: computedfield vs entity_reference base field to help confirm @damienmckenna
Comment #264
tame4tex commentedI can't see where in the code the Select list maximum number of options of 100 gets applied. I just did a manual test with 103 options and they all appeared in the select list.
Is this an oversight? Should the number of options be limited to 100?
Switching back to Needs Work (Sorry!)
Comment #265
tame4tex commentedActually NVM, sorry my bad, I see where it is being applied.
This is not an issue with this code, it is a method further along the call tree in
\Drupal\views\Plugin\EntityReferenceSelection\ViewsSelection::getReferenceableEntitiesthat is not respecting the limit. I will investigate further and open a separate issue if need be.Switching back to Reviewed & tested by the community. Sorry for the noise!
Comment #266
tame4tex commentedFor those interested, I have added an issue and MR to re-add the functionality that switches a select widget to an autocomplete widget when the number of options hits a predetermined limit.
See #3481590: Views EntityReference filter: Add functionality to switch from select to autocomplete widget when a max number of options reached
Comment #267
trackleft2I've been testing this on a local site using a custom config entity and it works wonderfully, the only issue I found was that if I publish or unpublish some of the target entities they aren't removed from the select options for anonymous users until cache is cleared/rebuilt.
With that said, I approve of merging this as - is.
A possible follow-up could be to add cache tags to the select element in
valueFormAddSelectlike this.And a helper method like this.
Or however you would integrate these new cache tags into the view.
calculateDependencies()?Anyway, I think the above fix worked for me.
Comment #270
catch@trackleft2 thanks for the additional testing. If you could open a follow-up for cache tags in the selection plugin that sounds good.
Since we don't have further details about issues that people have run into, or they turned out not to be an issue with this MR, going ahead with the 10.4.x backport here.
Committed/pushed to 10.4.x, thanks!
Comment #271
catchThis is only API-facing at the moment but adding to 11.1.0 release highlights just in case we want to include it.
Comment #276
webflo commented@catch Commit 43732e22 never made it Drupal 11. It is in 10.4.x and 10.5.x only
Comment #277
bramdriesen@webflo, I see a commit on 11.x.
https://www.drupal.org/project/drupal/issues/3347343#comment-15714999
https://git.drupalcode.org/project/drupal/-/commits/11.x?search=%233347343
Comment #278
ahlam aljawahreh commented@catch I updated to D10.4 ,is the Commit 43732e22 work for the custom entity types?
#545 was working like a charm for me, without any views updates. Now I need to add custom code for custom entity types and update all views where I used the entity reference view filter
please let me know if I missed something.
Comment #279
jonmcl commentedMy understanding is that only Node and Term work out of the box. It will be up to each module to enable their custom entity type.
Or, if you build your own, I think you want to look at https://www.drupal.org/project/views_core_entity_reference
When I installed it I had to manually run the hook_update_N function to modify your existing views configs to work with the latest code.
Comment #280
acbramley commentedThanks a lot @scott_euser for the module, after upgrading to 10.4 and removing the 10.3 patch I was able to get filters working again by installing it.
However, there is one caveat - the filter config schema changed slightly from
handlerandhandler_settingstosub_handlerandsub_handler_settingsYou can re-edit your filters in views manually, or simply hand edit the yaml and do a config import.
Comment #281
acbramley commentedCreated a small bug report #3496886: Views entity_reference filter incompatible with TermSelection plugin
Comment #282
heddnre #280: my site's config was already using
sub_handlerandsub_handler_settingswith a recent version of the patch. I'm about to switch to the contrib module with the core code in 10.4.0, but wanted to provide this insight.Comment #283
scott_euser commentedYeah it's hard to cover all the conversions with the install hook as there have been so many versions over the months/years, but if you've got a specific source happy to add more options to the install hook. If you do add an MR with a new source there is a Kernel test to cover the update.
Re #279 yeah that was me not thinking it through, in dev branch in the module it's an install hook now instead of update hook as update hooks don't run on fresh install of the module. Haven't made a new release yet though.
Comment #284
wattdesigns commentedI think I'm in the right area, but if not, please let me know and I'll remove.
Drupal version 10.4.3
Views version 10.4.3 no patches
Here's what I need:
I need to filter an existing view by node titles with the titles sorted by posting date, in a pull down select list. This way, I can open the view, select the node title in the drop down, and only see views data for that node.
This used to be super easy in Drupal 7, as I would make a filter using a referenced separate view that provided the title and had a hidden post date to sort by.
Now that's gone and I'm floundering.
I have an Entity View that has the node titles and post date, and sorts by the post date. So that's the data I want in the pull down.
How do I make the view filter do that now?
If this module fixes things for me, do I use the dev or alpha versions as they appear to be slightly different.
Thanks so much!!!! This is driving me bonkers!
Comment #285
scott_euser commentedCheck out the "Views Core Entity Reference" module - you should be able to do just that - hope it helps!
Comment #286
wattdesigns commentedI did! It does look like what I wanted (so I'm glad I'm on the right track), but I'm having issues making it work. Do you have some instructions? I'm good with installing the module, but not sure how it plugs into views to make the filter. I've made other filters before, so I'm good there too. I'm just missing something.
Comment #287
scott_euser commentedI'll send you a direct message (just conscious this issue has a lot of followers from when it was under construction)
Comment #288
balagan commentedComment #289
balagan commentedComment #290
dwwFYI: I opened #3517303: [PP-1] Use the new 'entity_reference' Views filter in EntityViewsData::processViewsDataForEntityReference() which should help considerably. 😅
Comment #291
xjmAmending attribution.