1 | <?php |
||
33 | class IFrame extends DisplayBase implements DisplayRouterInterface { |
||
34 | |||
35 | /** |
||
36 | * Current route match service. |
||
37 | * |
||
38 | * @var \Drupal\Core\Routing\RouteMatchInterface |
||
39 | */ |
||
40 | protected $currentRouteMatch; |
||
41 | |||
42 | /** |
||
43 | * Current path. |
||
44 | * |
||
45 | * @var \Drupal\Core\Path\CurrentPathStack |
||
46 | */ |
||
47 | protected $currentPath; |
||
48 | |||
49 | /** |
||
50 | * Current request. |
||
51 | * |
||
52 | * @var \Symfony\Component\HttpFoundation\Request |
||
53 | */ |
||
54 | protected $request; |
||
55 | |||
56 | /** |
||
57 | * Constructs display plugin. |
||
58 | * |
||
59 | * @param array $configuration |
||
60 | * A configuration array containing information about the plugin instance. |
||
61 | * @param string $plugin_id |
||
62 | * The plugin_id for the plugin instance. |
||
63 | * @param mixed $plugin_definition |
||
64 | * The plugin implementation definition. |
||
65 | * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher |
||
66 | * Event dispatcher service. |
||
67 | * @param \Drupal\Component\Uuid\UuidInterface $uuid |
||
68 | * UUID generator interface. |
||
69 | * @param \Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface $selection_storage |
||
70 | * The selection storage. |
||
71 | * @param \Drupal\Core\Routing\RouteMatchInterface $current_route_match |
||
72 | * The currently active route match object. |
||
73 | * @param \Symfony\Component\HttpFoundation\Request $request |
||
74 | * Current request. |
||
75 | * @param \Drupal\Core\Path\CurrentPathStack $current_path |
||
76 | * The current path. |
||
77 | */ |
||
78 | public function __construct(array $configuration, $plugin_id, $plugin_definition, EventDispatcherInterface $event_dispatcher, UuidInterface $uuid, KeyValueStoreExpirableInterface $selection_storage, RouteMatchInterface $current_route_match, Request $request, CurrentPathStack $current_path) { |
||
84 | |||
85 | /** |
||
86 | * {@inheritdoc} |
||
87 | */ |
||
88 | public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { |
||
89 | return new static( |
||
90 | $configuration, |
||
91 | $plugin_id, |
||
92 | $plugin_definition, |
||
93 | $container->get('event_dispatcher'), |
||
94 | $container->get('uuid'), |
||
95 | $container->get('entity_browser.selection_storage'), |
||
96 | $container->get('current_route_match'), |
||
97 | $container->get('request_stack')->getCurrentRequest(), |
||
98 | $container->get('path.current') |
||
99 | ); |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * {@inheritdoc} |
||
104 | */ |
||
105 | public function defaultConfiguration() { |
||
106 | return [ |
||
107 | 'width' => '650', |
||
108 | 'height' => '500', |
||
109 | 'link_text' => $this->t('Select entities'), |
||
110 | 'auto_open' => FALSE, |
||
111 | ] + parent::defaultConfiguration(); |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * {@inheritdoc} |
||
116 | */ |
||
117 | public function displayEntityBrowser(array $element, FormStateInterface $form_state, array &$complete_form, array $persistent_data = []) { |
||
175 | |||
176 | /** |
||
177 | * KernelEvents::RESPONSE listener. |
||
178 | * |
||
179 | * Intercepts default response and injects response that will trigger JS to |
||
180 | * propagate selected entities upstream. |
||
181 | * |
||
182 | * @param FilterResponseEvent $event |
||
183 | * Response event. |
||
184 | */ |
||
185 | public function propagateSelection(FilterResponseEvent $event) { |
||
186 | $render = [ |
||
187 | 'labels' => [ |
||
188 | '#markup' => 'Labels: ' . implode(', ', array_map(function (EntityInterface $item) { |
||
189 | return $item->label(); |
||
190 | }, $this->entities)), |
||
191 | '#attached' => [ |
||
192 | 'library' => ['entity_browser/'. $this->pluginDefinition['id'] . '_selection'], |
||
193 | 'drupalSettings' => [ |
||
194 | 'entity_browser' => [ |
||
195 | $this->pluginDefinition['id'] => [ |
||
196 | 'entities' => array_map(function (EntityInterface $item) { |
||
197 | return [$item->id(), $item->uuid(), $item->getEntityTypeId()]; |
||
198 | }, $this->entities), |
||
199 | 'uuid' => $this->request->query->get('uuid'), |
||
200 | ], |
||
201 | ], |
||
202 | ], |
||
203 | ], |
||
204 | ], |
||
205 | ]; |
||
206 | |||
207 | $event->setResponse(new Response(\Drupal::service('bare_html_page_renderer')->renderBarePage($render, 'Entity browser', 'page'))); |
||
208 | } |
||
209 | |||
210 | /** |
||
211 | * {@inheritdoc} |
||
212 | */ |
||
213 | public function path() { |
||
216 | |||
217 | /** |
||
218 | * {@inheritdoc} |
||
219 | */ |
||
220 | public function buildConfigurationForm(array $form, FormStateInterface $form_state) { |
||
250 | |||
251 | /** |
||
252 | * {@inheritdoc} |
||
253 | */ |
||
254 | public function validateConfigurationForm(array &$form, FormStateInterface $form_state) { |
||
265 | |||
266 | } |
||
267 |