3 namespace Drupal\views\Plugin\Derivative;
5 use Drupal\Core\Entity\EntityManagerInterface;
6 use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
7 use Drupal\views\ViewsData;
8 use Symfony\Component\DependencyInjection\ContainerInterface;
11 * Provides views row plugin definitions for all non-special entity types.
13 * @ingroup views_row_plugins
15 * @see \Drupal\views\Plugin\views\row\EntityRow
17 class ViewsEntityRow implements ContainerDeriverInterface {
20 * Stores all entity row plugin information.
24 protected $derivatives = [];
27 * The base plugin ID that the derivative is for.
31 protected $basePluginId;
36 * @var \Drupal\Core\Entity\EntityManagerInterface
38 protected $entityManager;
41 * The views data service.
43 * @var \Drupal\views\ViewsData
48 * Constructs a ViewsEntityRow object.
50 * @param string $base_plugin_id
52 * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
54 * @param \Drupal\views\ViewsData $views_data
55 * The views data service.
57 public function __construct($base_plugin_id, EntityManagerInterface $entity_manager, ViewsData $views_data) {
58 $this->basePluginId = $base_plugin_id;
59 $this->entityManager = $entity_manager;
60 $this->viewsData = $views_data;
66 public static function create(ContainerInterface $container, $base_plugin_id) {
69 $container->get('entity.manager'),
70 $container->get('views.views_data')
77 public function getDerivativeDefinition($derivative_id, $base_plugin_definition) {
78 if (!empty($this->derivatives) && !empty($this->derivatives[$derivative_id])) {
79 return $this->derivatives[$derivative_id];
81 $this->getDerivativeDefinitions($base_plugin_definition);
82 return $this->derivatives[$derivative_id];
88 public function getDerivativeDefinitions($base_plugin_definition) {
89 foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) {
90 // Just add support for entity types which have a views integration.
91 if (($base_table = $entity_type->getBaseTable()) && $this->viewsData->get($base_table) && $this->entityManager->hasHandler($entity_type_id, 'view_builder')) {
92 $this->derivatives[$entity_type_id] = [
93 'id' => 'entity:' . $entity_type_id,
94 'provider' => 'views',
95 'title' => $entity_type->getLabel(),
96 'help' => t('Display the @label', ['@label' => $entity_type->getLabel()]),
97 'base' => [$entity_type->getDataTable() ?: $entity_type->getBaseTable()],
98 'entity_type' => $entity_type_id,
99 'display_types' => ['normal'],
100 'class' => $base_plugin_definition['class'],
105 return $this->derivatives;