You are here

function entity_views_data in Entity API 8

Same name and namespace in other branches
  1. 8.0 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
      ->entityClassImplements(ContentEntityInterface::class);
  });
  $data = [];
  foreach ($entity_types as $entity_type) {

    /** @var \Drupal\Core\Entity\EntityTypeInterface $entity_type */
    if ($entity_type
      ->isRevisionable()) {
      $entity_type_id = $entity_type
        ->id();
      $revision_table = $entity_type
        ->getRevisionDataTable() ?: $entity_type
        ->getRevisionTable();
      if ($entity_type
        ->hasLinkTemplate('revision')) {
        $data[$revision_table]['view_revision_' . $entity_type_id] = [
          'field' => [
            'title' => t('Link to revision'),
            'help' => t('Provide a simple link to the revision.'),
            'id' => 'entity_link_revision',
            'click sortable' => FALSE,
          ],
        ];
      }
      if ($entity_type
        ->hasLinkTemplate('revision-revert-form')) {
        $data[$revision_table]['revert_revision_' . $entity_type_id] = [
          'field' => [
            'title' => t('Link to revert revision'),
            'help' => t('Provide a simple link to revert to the revision.'),
            'id' => 'entity_link_revision_revert',
            'click sortable' => FALSE,
          ],
        ];
      }
    }
  }
  return $data;
}