entity.views.inc 918 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. use Drupal\Core\Entity\ContentEntityInterface;
  3. use Drupal\Core\Entity\EntityTypeInterface;
  4. /**
  5. * Implements hook_views_data().
  6. */
  7. function entity_views_data() {
  8. $entity_types = \Drupal::entityTypeManager()->getDefinitions();
  9. $entity_types = array_filter($entity_types, function (EntityTypeInterface $entity_type) {
  10. return $entity_type->entityClassImplements(ContentEntityInterface::class);
  11. });
  12. $data = [];
  13. foreach ($entity_types as $entity_type) {
  14. /** @var \Drupal\Core\Entity\EntityTypeInterface $entity_type */
  15. $base_table = $entity_type->getBaseTable() ?: $entity_type->id();
  16. if ($entity_type->hasViewBuilderClass()) {
  17. $data[$base_table]['rendered_entity'] = [
  18. 'field' => [
  19. 'title' => t('Rendered entity'),
  20. 'help' => t('Renders an entity in a view mode.'),
  21. 'id' => 'rendered_entity',
  22. ],
  23. ];
  24. }
  25. }
  26. return $data;
  27. }