Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/views/src/Plugin/EntityReferenceSelection/ViewsSelection.php @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | a9cd425dd02b |
children |
comparison
equal
deleted
inserted
replaced
4:a9cd425dd02b | 5:12f9dff5fda9 |
---|---|
1 <?php | 1 <?php |
2 | 2 |
3 namespace Drupal\views\Plugin\EntityReferenceSelection; | 3 namespace Drupal\views\Plugin\EntityReferenceSelection; |
4 | 4 |
5 use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait; | |
5 use Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginBase; | 6 use Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginBase; |
6 use Drupal\Core\Entity\EntityReferenceSelection\SelectionTrait; | 7 use Drupal\Core\Entity\EntityTypeManagerInterface; |
8 use Drupal\Core\Extension\ModuleHandlerInterface; | |
7 use Drupal\Core\Form\FormStateInterface; | 9 use Drupal\Core\Form\FormStateInterface; |
8 use Drupal\Core\Plugin\ContainerFactoryPluginInterface; | 10 use Drupal\Core\Plugin\ContainerFactoryPluginInterface; |
11 use Drupal\Core\Session\AccountInterface; | |
9 use Drupal\Core\Url; | 12 use Drupal\Core\Url; |
10 use Drupal\views\Views; | 13 use Drupal\views\Views; |
14 use Symfony\Component\DependencyInjection\ContainerInterface; | |
11 | 15 |
12 /** | 16 /** |
13 * Plugin implementation of the 'selection' entity_reference. | 17 * Plugin implementation of the 'selection' entity_reference. |
14 * | 18 * |
15 * @EntityReferenceSelection( | 19 * @EntityReferenceSelection( |
18 * group = "views", | 22 * group = "views", |
19 * weight = 0 | 23 * weight = 0 |
20 * ) | 24 * ) |
21 */ | 25 */ |
22 class ViewsSelection extends SelectionPluginBase implements ContainerFactoryPluginInterface { | 26 class ViewsSelection extends SelectionPluginBase implements ContainerFactoryPluginInterface { |
23 | 27 use DeprecatedServicePropertyTrait; |
24 use SelectionTrait; | 28 |
29 /** | |
30 * {@inheritdoc} | |
31 */ | |
32 protected $deprecatedProperties = ['entityManager' => 'entity.manager']; | |
25 | 33 |
26 /** | 34 /** |
27 * The loaded View object. | 35 * The loaded View object. |
28 * | 36 * |
29 * @var \Drupal\views\ViewExecutable | 37 * @var \Drupal\views\ViewExecutable |
30 */ | 38 */ |
31 protected $view; | 39 protected $view; |
40 | |
41 /** | |
42 * The entity type manager service. | |
43 * | |
44 * @var \Drupal\Core\Entity\EntityManagerInterface | |
45 */ | |
46 protected $entityTypeManager; | |
47 | |
48 /** | |
49 * The module handler service. | |
50 * | |
51 * @var \Drupal\Core\Extension\ModuleHandlerInterface | |
52 */ | |
53 protected $moduleHandler; | |
54 | |
55 /** | |
56 * The current user. | |
57 * | |
58 * @var \Drupal\Core\Session\AccountInterface | |
59 */ | |
60 protected $currentUser; | |
61 | |
62 /** | |
63 * Constructs a new ViewsSelection object. | |
64 * | |
65 * @param array $configuration | |
66 * A configuration array containing information about the plugin instance. | |
67 * @param string $plugin_id | |
68 * The plugin_id for the plugin instance. | |
69 * @param mixed $plugin_definition | |
70 * The plugin implementation definition. | |
71 * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager | |
72 * The entity type manager service. | |
73 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler | |
74 * The module handler service. | |
75 * @param \Drupal\Core\Session\AccountInterface $current_user | |
76 * The current user. | |
77 */ | |
78 public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler, AccountInterface $current_user) { | |
79 parent::__construct($configuration, $plugin_id, $plugin_definition); | |
80 | |
81 $this->entityTypeManager = $entity_type_manager; | |
82 $this->moduleHandler = $module_handler; | |
83 $this->currentUser = $current_user; | |
84 } | |
85 | |
86 /** | |
87 * {@inheritdoc} | |
88 */ | |
89 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { | |
90 return new static( | |
91 $configuration, | |
92 $plugin_id, | |
93 $plugin_definition, | |
94 $container->get('entity_type.manager'), | |
95 $container->get('module_handler'), | |
96 $container->get('current_user') | |
97 ); | |
98 } | |
32 | 99 |
33 /** | 100 /** |
34 * {@inheritdoc} | 101 * {@inheritdoc} |
35 */ | 102 */ |
36 public function defaultConfiguration() { | 103 public function defaultConfiguration() { |
51 | 118 |
52 $view_settings = $this->getConfiguration()['view']; | 119 $view_settings = $this->getConfiguration()['view']; |
53 $displays = Views::getApplicableViews('entity_reference_display'); | 120 $displays = Views::getApplicableViews('entity_reference_display'); |
54 // Filter views that list the entity type we want, and group the separate | 121 // Filter views that list the entity type we want, and group the separate |
55 // displays by view. | 122 // displays by view. |
56 $entity_type = $this->entityManager->getDefinition($this->configuration['target_type']); | 123 $entity_type = $this->entityTypeManager->getDefinition($this->configuration['target_type']); |
57 $view_storage = $this->entityManager->getStorage('view'); | 124 $view_storage = $this->entityTypeManager->getStorage('view'); |
58 | 125 |
59 $options = []; | 126 $options = []; |
60 foreach ($displays as $data) { | 127 foreach ($displays as $data) { |
61 list($view_id, $display_id) = $data; | 128 list($view_id, $display_id) = $data; |
62 $view = $view_storage->load($view_id); | 129 $view = $view_storage->load($view_id); |