3 namespace Drupal\Core\Entity\EntityReferenceSelection;
5 use Drupal\Core\Entity\EntityManagerInterface;
6 use Drupal\Core\Extension\ModuleHandlerInterface;
7 use Drupal\Core\Session\AccountInterface;
8 use Symfony\Component\DependencyInjection\ContainerInterface;
11 * Provides common methods and injects services for core selection handlers.
13 trait SelectionTrait {
16 * The entity manager service.
18 * @var \Drupal\Core\Entity\EntityManagerInterface
20 protected $entityManager;
23 * The module handler service.
25 * @var \Drupal\Core\Extension\ModuleHandlerInterface
27 protected $moduleHandler;
32 * @var \Drupal\Core\Session\AccountInterface
34 protected $currentUser;
37 * Constructs a new selection object.
39 * @param array $configuration
40 * A configuration array containing information about the plugin instance.
41 * @param string $plugin_id
42 * The plugin_id for the plugin instance.
43 * @param mixed $plugin_definition
44 * The plugin implementation definition.
45 * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
46 * The entity manager service.
47 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
48 * The module handler service.
49 * @param \Drupal\Core\Session\AccountInterface $current_user
52 public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityManagerInterface $entity_manager, ModuleHandlerInterface $module_handler, AccountInterface $current_user) {
53 parent::__construct($configuration, $plugin_id, $plugin_definition);
55 $this->entityManager = $entity_manager;
56 $this->moduleHandler = $module_handler;
57 $this->currentUser = $current_user;
63 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
68 $container->get('entity.manager'),
69 $container->get('module_handler'),
70 $container->get('current_user')