You are here

function moderation_dashboard_views_data in Moderation Dashboard 8

Same name and namespace in other branches
  1. 2.0.x moderation_dashboard.module \moderation_dashboard_views_data()

Implements hook_views_data().

File

./moderation_dashboard.module, line 15
Contains hooks for the moderation_dashboard module.

Code

function moderation_dashboard_views_data() {
  $data = [];
  $manager = \Drupal::entityTypeManager();

  /** @var \Drupal\Core\Entity\ContentEntityTypeInterface[] $entity_types */
  $entity_types = array_filter($manager
    ->getDefinitions(), function (EntityTypeInterface $entity_type) {
    return $entity_type instanceof ContentEntityTypeInterface && $entity_type
      ->isRevisionable() && $entity_type
      ->hasHandlerClass('views_data');
  });
  foreach ($entity_types as $id => $entity_type) {
    $table = $manager
      ->getHandler($id, 'views_data')
      ->getViewsTableForEntityType($entity_type);
    $data[$table]['link_to_latest_version'] = [
      'title' => t('Link to latest version'),
      'field' => [
        'id' => 'link_to_latest_version',
        'real field' => $entity_type
          ->getKey('id'),
      ],
    ];
  }
  return $data;
}