3 namespace Drupal\views\Plugin\Derivative;
5 use Drupal\Component\Plugin\Derivative\DeriverBase;
6 use Drupal\Core\Entity\EntityManagerInterface;
7 use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
8 use Drupal\Core\StringTranslation\StringTranslationTrait;
9 use Drupal\Core\StringTranslation\TranslationInterface;
10 use Symfony\Component\DependencyInjection\ContainerInterface;
13 * Provides views argument validator plugin definitions for all entity types.
15 * @ingroup views_argument_validator_plugins
17 * @see \Drupal\views\Plugin\views\argument_validator\Entity
19 class ViewsEntityArgumentValidator extends DeriverBase implements ContainerDeriverInterface {
20 use StringTranslationTrait;
23 * The base plugin ID this derivative is for.
27 protected $basePluginId;
32 * @var \Drupal\Core\Entity\EntityManagerInterface
34 protected $entityManager;
37 * List of derivative definitions.
41 protected $derivatives = [];
44 * Constructs an ViewsEntityArgumentValidator object.
46 * @param string $base_plugin_id
48 * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
50 * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
51 * The string translation.
53 public function __construct($base_plugin_id, EntityManagerInterface $entity_manager, TranslationInterface $string_translation) {
54 $this->basePluginId = $base_plugin_id;
55 $this->entityManager = $entity_manager;
56 $this->stringTranslation = $string_translation;
62 public static function create(ContainerInterface $container, $base_plugin_id) {
65 $container->get('entity.manager'),
66 $container->get('string_translation')
73 public function getDerivativeDefinitions($base_plugin_definition) {
74 $entity_types = $this->entityManager->getDefinitions();
75 $this->derivatives = [];
76 foreach ($entity_types as $entity_type_id => $entity_type) {
77 $this->derivatives[$entity_type_id] = [
78 'id' => 'entity:' . $entity_type_id,
79 'provider' => 'views',
80 'title' => $entity_type->getLabel(),
81 'help' => $this->t('Validate @label', ['@label' => $entity_type->getLabel()]),
82 'entity_type' => $entity_type_id,
83 'class' => $base_plugin_definition['class'],
87 return $this->derivatives;