Clean up getViewsData() in NodeViewsData

Created on 9 November 2018, over 6 years ago
Updated 19 March 2025, about 2 months ago

Problem/Motivation

The file NodeViewsData.php, which implements a single function, getViewsData() should be a model of good organization and well documented.

This function returns an array with the structure documented in hook_views_data(). It is pretty complicated, with a lot of options. (In other words, not all of Drupal 7's info arrays were replaced by more object-oriented structures.) Anyone who has to implement that hook, or the related alter hook, and wants more examples than in the API documentation is going to look first at NodeViewsData.php. It has a lot of examples that affect options (fields, sorts, relations) that are familiar to anyone who has used Views.

Proposed resolution

Add an @see comment pointing to the documentation for hook_views_data().

Reorganize the function so that everything related to one primary key is in the same place. As it is now, I see a few lines related to $data['node']['node_bulk_form'], and later more lines for $data['node']['node_listing_empty'], interrupting the long definition of $data['node_field_data'].

Consider splitting off into a separate function the part that applies only if the Search module is enabled.

Add code comments explaining how each section affects what a site builder sees when working with Views.

Remaining tasks

User interface changes

None. This issue is all about developer experience (DX). If it is done correctly, it will have no effect on functionality nor interface.

API changes

None

Data model changes

None

πŸ“Œ Task
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component

node system

Created by

πŸ‡ΊπŸ‡ΈUnited States benjifisher Boston area

Live updates comments and jobs are added and updated live.
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.

  • πŸ‡¦πŸ‡ΊAustralia acbramley

    I agree this file could use some love. We even have some fun comments like // Bogus fields for aliasing purposes.

    We need a bit more of a plan here about what we should do though.

Production build 0.71.5 2024