Add a ViewsData class to make the example content entity visible to the Views module.

I have created a patch.

Comments

tetranz created an issue. See original summary.

tetranz’s picture

StatusFileSize
new2.57 KB

My ContactViewsData class is very simple but it does illustrate where to modify the default data to change how the entity appears to Views.

There is an existing comment with a @todo in the Entity class when talking about the list_builder. I have not seen any other reference to the list_builder being automatically overridden by a view. I'm not sure if that is still valid.

tetranz’s picture

Status: Active » Needs review
mile23’s picture

Status: Needs review » Needs work

I like this idea. We should have a test to verify that it works and continues to work going forward.

Also a couple other things:

  1. +++ b/content_entity_example/src/Entity/ContactViewsData.php
    @@ -0,0 +1,40 @@
    +/**
    + * @file
    + * Contains Drupal\content_entity_example\ContactViewsData.
    + */
    

    We don't use @file any more.

  2. +++ b/content_entity_example/src/Entity/ContactViewsData.php
    @@ -0,0 +1,40 @@
    +    // The data is in the format of hook_views_data()
    +    // See documentation here:
    +    // https://api.drupal.org/api/drupal/core!modules!views!views.api.php/function/hook_views_data/8.2.x
    

    Make this a @see, and update it to point to 8.3.x

dhruveshdtripathi’s picture

Status: Needs work » Needs review
StatusFileSize
new2.43 KB
new966 bytes

Made changes suggested in comment #4

Patch and Interdiff attached.

Thank you

mile23’s picture

Status: Needs review » Needs work
Issue tags: -views, -entity +Needs tests

Thanks, @dhruveshdtripathi.

Still needs a test to verify that it works and to make sure it's maintainable.

tetranz’s picture

Assigned: tetranz » Unassigned

Sorry, I probably should have unassigned myself long ago.

avpaderno’s picture

Component: Content Entity Example » Code
Issue tags: +Needs merge request
avpaderno’s picture

Title: Add a ViewsData class to make the entity visible to Views. » Add a ViewsData class to make the entity visible to views