Bundle.php in Drupal 8
File
core/modules/views/src/Plugin/views/filter/Bundle.php
View source
<?php
namespace Drupal\views\Plugin\views\filter;
use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
class Bundle extends InOperator {
use DeprecatedServicePropertyTrait;
protected $deprecatedProperties = [
'entityManager' => 'entity.manager',
];
protected $entityTypeId;
protected $entityType;
protected $entityTypeManager;
protected $bundleInfoService;
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $bundle_info_service) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entity_type_manager;
$this->bundleInfoService = $bundle_info_service;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('entity_type.manager'), $container
->get('entity_type.bundle.info'));
}
public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
parent::init($view, $display, $options);
$this->entityTypeId = $this
->getEntityType();
$this->entityType = \Drupal::entityTypeManager()
->getDefinition($this->entityTypeId);
$this->real_field = $this->entityType
->getKey('bundle');
}
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;
}
public function query() {
$this
->ensureMyTable();
parent::query();
}
public function calculateDependencies() {
$dependencies = parent::calculateDependencies();
$bundle_entity_type = $this->entityType
->getBundleEntityType();
$bundle_entity_storage = $this->entityTypeManager
->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;
}
}
Classes
Name |
Description |
Bundle |
Filter class which allows filtering by entity bundles. |