entityManager = $entity_manager; $this->bundleInfoService = $bundle_info_service; } /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { return new static( $configuration, $plugin_id, $plugin_definition, $container->get('entity.manager'), $container->get('entity_type.bundle.info') ); } /** * {@inheritdoc} */ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { parent::init($view, $display, $options); $this->entityTypeId = $this->getEntityType(); $this->entityType = \Drupal::entityManager()->getDefinition($this->entityTypeId); $this->real_field = $this->entityType->getKey('bundle'); } /** * {@inheritdoc} */ public function getValueOptions() { if (!isset($this->valueOptions)) { $types = $this->bundleInfoService->getBundleInfo($this->entityTypeId); $this->valueTitle = $this->t('@entity types', ['@entity' => $this->entityType->getLabel()]); $options = []; foreach ($types as $type => $info) { $options[$type] = $info['label']; } asort($options); $this->valueOptions = $options; } return $this->valueOptions; } /** * {@inheritdoc} */ public function query() { // Make sure that the entity base table is in the query. $this->ensureMyTable(); parent::query(); } /** * {@inheritdoc} */ public function calculateDependencies() { $dependencies = parent::calculateDependencies(); $bundle_entity_type = $this->entityType->getBundleEntityType(); $bundle_entity_storage = $this->entityManager->getStorage($bundle_entity_type); foreach (array_keys($this->value) as $bundle) { if ($bundle_entity = $bundle_entity_storage->load($bundle)) { $dependencies[$bundle_entity->getConfigDependencyKey()][] = $bundle_entity->getConfigDependencyName(); } } return $dependencies; } }