You are here

function entity_views_data in Entity API 8.0

Same name and namespace in other branches
  1. 8 entity.views.inc \entity_views_data()
  2. 7 views/entity.views.inc \entity_views_data()

Implements hook_views_data().

File

./entity.views.inc, line 9

Code

function entity_views_data() {
  $entity_types = \Drupal::entityTypeManager()
    ->getDefinitions();
  $entity_types = array_filter($entity_types, function (EntityTypeInterface $entity_type) {
    return $entity_type
      ->isSubclassOf(ContentEntityInterface::class);
  });
  $data = [];
  foreach ($entity_types as $entity_type) {

    /** @var \Drupal\Core\Entity\EntityTypeInterface $entity_type */
    $base_table = $entity_type
      ->getBaseTable() ?: $entity_type
      ->id();
    if ($entity_type
      ->hasViewBuilderClass()) {
      $data[$base_table]['rendered_entity'] = [
        'field' => [
          'title' => t('Rendered entity'),
          'help' => t('Renders an entity in a view mode.'),
          'id' => 'rendered_entity',
        ],
      ];
    }
  }
  return $data;
}