SelectionInterface::entityQueryAlter() is not invoked when using the ViewsSelection ER handler

Created on 10 February 2016, over 9 years ago
Updated 4 September 2025, 13 days ago

Problem/Motivation

Any handlers using the DefaultSelection handler are able to either easily extend DefaultSelection and override entityQueryAlter() or alter the query themselves using hook_query_TAG_alter, like system module does to actually invoke entityQueryAlter().

However, when using the ViewsSelection handler these tags and metadata or not added to the view. This means that hook_query_TAG_alter and subsequently the entityQueryAlter() method on the interface itself are never called.

I was looking at using this functionality in OG, but hit a road block with this problem, as we cannot currently rely on using the SelectionInterface.

Proposed resolution

Make sure ViewsSelection behaves the same as the DefaultSelection handler, and SelectionInterface::alterEntityQuery() actually works.

The current problem is that the views query plugins are not capable of adding arbitrary metadata like our Query objects can. We should have a method for adding this that behaves like addTag. We should also move addTag() to the QueryPluginBase method instead of the Sql plugin so we can rely on it being there in a more generic way, regardless of the query backend.

We can then add the correct tag and metadata. So there will be parity with the DefaultSelection handler, and thus, peace will be restored.

Remaining tasks

User interface changes

N/A

API changes

New method on QueryPluginBase in views. Technically I think this is fine, as QueryPluginBase is typehinted in a few places, so anyone would have to extend this anyway.

Data model changes

πŸ“Œ Task
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component

views.module

Created by

πŸ‡¬πŸ‡§United Kingdom damiankloip

Live updates comments and jobs are added and updated live.
  • VDC

    Related to the Views in Drupal Core initiative.

  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

  • Triaged core major

    There is consensus among core maintainers that this is a major issue. Only core committers should add this tag.

  • stale-issue-cleanup

    To track issues in the developing policy for closing stale issues, [Policy, no patch] closing older issues

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Thank you for creating this issue to improve Drupal.

    We are working to decide if this task is still relevant to a currently supported version of Drupal. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or is no longer relevant. Your thoughts on this will allow a decision to be made.

    Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

    Thanks!

Production build 0.71.5 2024