basePluginId = $base_plugin_id; $this->entityManager = $entity_manager; $this->viewsData = $views_data; } /** * {@inheritdoc} */ public static function create(ContainerInterface $container, $base_plugin_id) { return new static( $base_plugin_id, $container->get('entity.manager'), $container->get('views.views_data') ); } /** * {@inheritdoc} */ public function getDerivativeDefinition($derivative_id, $base_plugin_definition) { if (!empty($this->derivatives) && !empty($this->derivatives[$derivative_id])) { return $this->derivatives[$derivative_id]; } $this->getDerivativeDefinitions($base_plugin_definition); return $this->derivatives[$derivative_id]; } /** * {@inheritdoc} */ public function getDerivativeDefinitions($base_plugin_definition) { foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) { // Just add support for entity types which have a views integration. if (($base_table = $entity_type->getBaseTable()) && $this->viewsData->get($base_table) && $this->entityManager->hasHandler($entity_type_id, 'view_builder')) { $this->derivatives[$entity_type_id] = [ 'id' => 'entity:' . $entity_type_id, 'provider' => 'views', 'title' => $entity_type->getLabel(), 'help' => t('Display the @label', ['@label' => $entity_type->getLabel()]), 'base' => [$entity_type->getDataTable() ?: $entity_type->getBaseTable()], 'entity_type' => $entity_type_id, 'display_types' => ['normal'], 'class' => $base_plugin_definition['class'], ]; } } return $this->derivatives; } }