contacts_events-8.x-1.x-dev/src/Plugin/views/filter/State.php
src/Plugin/views/filter/State.php
<?php
namespace Drupal\contacts_events\Plugin\views\filter;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\state_machine\Plugin\views\filter\State as MachineState;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Filter by workflow state.
*
* Overrides GetBundles() to work around the fact that bundle fields don't get
* added to the field map.
*
* @see https://www.drupal.org/project/drupal/issues/3045509.
*
* @ingroup views_filter_handlers
*
* @ViewsFilter("contacts_state_machine_state")
*/
class State extends MachineState {
/**
* The entity bundle info service.
*
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
*/
protected $entityBundleInfo;
/**
* Constructs a new State object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
* The entity field manager.
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_bundle_info
* The entity bundle info service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, EntityFieldManagerInterface $entity_field_manager, EntityTypeBundleInfoInterface $entity_bundle_info) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_type_manager, $entity_field_manager);
$this->entityBundleInfo = $entity_bundle_info;
}
/**
* {@inheritdoc}
*/
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_field.manager'),
$container->get('entity_type.bundle.info')
);
}
/**
* {@inheritdoc}
*/
protected function getBundles(EntityTypeInterface $entity_type, $field_name) {
return array_keys($this->entityBundleInfo->getBundleInfo($entity_type->id()));
}
}
