Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[console] Is lack of Views support a console issue or Drupal core issue? #3780

Open
liquidcms opened this issue Feb 12, 2018 · 3 comments
Open

Comments

@liquidcms
Copy link

Problem/Motivation

I am building a new contrib module which has some custom entities. I used console to put the start of this together. The entities seem to work fine, i have written 100s of lines of code for the functionality of my module using these entities and i am close to being finished. From initial console build i see that i automatically get pages to manage my entities, manage fields, etc.. very cool.

I see 2 major issues though:

  1. manage entities page (maybe called my collection page) has no VBO sort of functionality (i.e. bulk delete or edit)
  2. if i go to create a View, even though Views knows about my new entity it knows nothing about the entity: title, id, fields, author, etc

My questions are not so much how to fix this.. but wondering where the disjoint is? Perhaps #1 is something Console could have added in? But, for #2 it seems like a core bug. Would Views not automatically know about fields in a custom entity? Or is this something that Console maybe should have added to the entity?

How to reproduce

Use console to make a custom entity.

Details to include:

  • Drupal version: 8.4.3
  • Console version: 1.5.0
  • Console Launcher version: 1.5.0 (doesnt run outside of Drupal install)
@liquidcms
Copy link
Author

I am now undecided as to where the bugs are in this. I turns out my console created module has duplicates for View types. For my module i have 2 different custom entities and each lists twice when selecting the type of View.

As it turns out one of the 2 has fields support and the other doesn't.

A little more trial and error (the only way in D8).. and i can see this code in MyEntityViewsData.php

namespace Drupal\reserve\Entity;

use Drupal\views\EntityViewsData;
use Drupal\views\EntityViewsDataInterface;

/**
 * Provides Views data for Reservation Category entities.
 */
class ReserveCategoryViewsData extends EntityViewsData implements EntityViewsDataInterface {

  /**
   * {@inheritdoc}
   */
  public function getViewsData() {
    $data = parent::getViewsData();

    $data['reserve_category']['table']['base'] = array(
      'field' => 'id',
      'title' => $this->t('Reservation Category'),
      'help' => $this->t('The Reservation Category ID.'),
    );

    return $data;
  }

}

And, if i leave the file in place but remove the getViewsData, then my useless 2nd View type (with no field support) goes away. I have built a view (as best i could with the bugs in Views) using the view type which remains, and it seems to mostly work as expected.

Still not sure if this is a bug in console but i'd guess not keeping up with Views changes.

@LOBsTerr
Copy link
Member

@liquidcms To make custom content entity visible for views we need to implement hook_views_data() -
https://api.drupal.org/api/drupal/core!modules!views!views.api.php/function/hook_views_data/8

I will give it a try and then I will check other problems

@liquidcms
Copy link
Author

liquidcms commented Feb 26, 2018

Part of this has gone away:

if i go to create a View, even though Views knows about my new entity it knows nothing about the entity: title, id, fields, author, etc

for some reason i ended up with new View types for each entity type created by Console. One is useless as it has no field support for Views, the other works fine. I manually removed some of the code written out by console to remove the bad one - and then it was good.

But yes, first issue:

manage entities page (maybe called my collection page) has no VBO sort of functionality (i.e. bulk delete or edit)

would be better if more functional (but easy to manually build once i found the right views type to use).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants