Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By larowlan on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.0.x
Introduced in version:
8.0-alpha15
Issue links:
Description:
hook_views_data()
for entity data was replaced with a new Views entity data object, since entity schemas are now generated automatically based on the entity itself. hook_views_data()
is still used for exposing other database tables to views.)
Drupal 7
/**
* Implements hook_views_data().
*
* Normally found in module.views.inc.
*/
function mymodule_views_data() {
// define views columns/intergration.
}
Drupal 8
In your entity annotation define an entry for views like so
* "views_data" = "Drupal\comment\CommentViewsData",
For example from comment module.
/**
* Defines the comment entity class.
*
* @ContentEntityType(
* id = "comment",
* label = @Translation("Comment"),
....
* handlers = {
* "views_data" = "Drupal\comment\CommentViewsData",
* },
Then define your Views data integration:
/**
* @file
* Contains \Drupal\comment\CommentViewsData.
*/
namespace Drupal\comment;
use Drupal\views\EntityViewsDataInterface;
/**
* Provides views data for the comment entity type.
*/
class CommentViewsData implements EntityViewsDataInterface {
/**
* {@inheritdoc}
*/
public function getViewsData() {
$data = array();
// Define your fields etc.
return $data;
}
}
Impacts:
Module developers