1d7947df21d2ae490581d842e31829b9406b2512
[yaffs-website] / SelectionTrait.php
1 <?php
2
3 namespace Drupal\Core\Entity\EntityReferenceSelection;
4
5 use Drupal\Core\Entity\EntityManagerInterface;
6 use Drupal\Core\Extension\ModuleHandlerInterface;
7 use Drupal\Core\Session\AccountInterface;
8 use Symfony\Component\DependencyInjection\ContainerInterface;
9
10 /**
11  * Provides common methods and injects services for core selection handlers.
12  */
13 trait SelectionTrait {
14
15   /**
16    * The entity manager service.
17    *
18    * @var \Drupal\Core\Entity\EntityManagerInterface
19    */
20   protected $entityManager;
21
22   /**
23    * The module handler service.
24    *
25    * @var \Drupal\Core\Extension\ModuleHandlerInterface
26    */
27   protected $moduleHandler;
28
29   /**
30    * The current user.
31    *
32    * @var \Drupal\Core\Session\AccountInterface
33    */
34   protected $currentUser;
35
36   /**
37    * Constructs a new selection object.
38    *
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
50    *   The current user.
51    */
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);
54
55     $this->entityManager = $entity_manager;
56     $this->moduleHandler = $module_handler;
57     $this->currentUser = $current_user;
58   }
59
60   /**
61    * {@inheritdoc}
62    */
63   public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
64     return new static(
65       $configuration,
66       $plugin_id,
67       $plugin_definition,
68       $container->get('entity.manager'),
69       $container->get('module_handler'),
70       $container->get('current_user')
71     );
72   }
73
74 }