Allow @FieldType to customize views data

Created on 12 September 2014, over 9 years ago
Updated 15 June 2023, 12 months ago

Problem/Motivation

Views integration works for config fields created in the UI, but not for base fields added to the entity types in code.

As an example, consider Date module. That diligently implements datetime_range_field_views_data() to declare its custom Views filters and arguments. But if I add a date field to my entity's base fields, the Views integration is completely missing.

Proposed resolution

Add the views handler to the field annotation as with the entity annotation. Provide the default base class for standard views data. Allow custom fields to have specific classes for views data.

Remaining tasks

Write a patch for the above proposed resolution.

User interface changes

None

API changes

API completion

Data model changes

None

Release notes snippet

TBC

πŸ“Œ Task
Status

Needs work

Version

11.0 πŸ”₯

Component
ViewsΒ  β†’

Last updated about 10 hours ago

Created by

πŸ‡©πŸ‡ͺGermany dawehner

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.

  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

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.

  • @joachim opened merge request.
  • πŸ‡¬πŸ‡§United Kingdom joachim

    Rebased branches, and made a new MR for 9.5.x.

    Not had time to consider the architectural questions raised by Berdir :(

    I wonder if plugin decoration would be a way to do this: #2958184: Allow decoration of plugins β†’ .

    Or we just specify a handler class name?

  • First commit to issue fork.
  • πŸ‡©πŸ‡ͺGermany geek-merlin Freiburg, Germany

    Amazing! Hiding patches iFo the MR.

  • πŸ‡¬πŸ‡§United Kingdom joachim

    I've just realised this is closely linked to hook_field_views_data_views_data_alter()

    The docs for that say:

    > The Views module's implementation of hook_views_data_alter() invokes this for each field storage, in the module that defines the field type. It is not invoked in other modules.

    So it's basically: the module defining the field type gets to say something about Views data. That hook is still needed, because it allows field type providers to do things like reverse entity references.

    But as a follow-up we could move that hook to the new handler classes that this issue will introduce.

Production build 0.69.0 2024