Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 313534

Clean up getViewsData() in NodeViewsData

$
0
0

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


Viewing all articles
Browse latest Browse all 313534

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>