1 | <?php |
||
21 | abstract class WidgetBase extends PluginBase implements WidgetInterface, ContainerFactoryPluginInterface { |
||
22 | |||
23 | use PluginConfigurationFormTrait; |
||
24 | |||
25 | /** |
||
26 | * Plugin id. |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $id; |
||
31 | |||
32 | /** |
||
33 | * Plugin uuid. |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $uuid; |
||
38 | /** |
||
39 | * Plugin label. |
||
40 | * |
||
41 | * @var string |
||
42 | */ |
||
43 | protected $label; |
||
44 | |||
45 | /** |
||
46 | * Plugin weight. |
||
47 | * |
||
48 | * @var int |
||
49 | */ |
||
50 | protected $weight; |
||
51 | |||
52 | /** |
||
53 | * Event dispatcher service. |
||
54 | * |
||
55 | * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface |
||
56 | */ |
||
57 | protected $eventDispatcher; |
||
58 | |||
59 | /** |
||
60 | * Entity manager service. |
||
61 | * |
||
62 | * @var \Drupal\Core\Entity\EntityManagerInterface |
||
63 | */ |
||
64 | protected $entityManager; |
||
65 | |||
66 | /** |
||
67 | * Constructs widget plugin. |
||
68 | * |
||
69 | * @param array $configuration |
||
70 | * A configuration array containing information about the plugin instance. |
||
71 | * @param string $plugin_id |
||
72 | * The plugin_id for the plugin instance. |
||
73 | * @param mixed $plugin_definition |
||
74 | * The plugin implementation definition. |
||
75 | * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher |
||
76 | * Event dispatcher service. |
||
77 | */ |
||
78 | public function __construct(array $configuration, $plugin_id, $plugin_definition, EventDispatcherInterface $event_dispatcher, EntityManagerInterface $entity_manager) { |
||
79 | parent::__construct($configuration, $plugin_id, $plugin_definition); |
||
80 | $this->eventDispatcher = $event_dispatcher; |
||
81 | $this->entityManager = $entity_manager; |
||
82 | $this->setConfiguration($configuration); |
||
83 | } |
||
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('entity.manager') |
||
95 | ); |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * {@inheritdoc} |
||
100 | */ |
||
101 | public function defaultConfiguration() { |
||
104 | |||
105 | /** |
||
106 | * {@inheritdoc} |
||
107 | */ |
||
108 | public function getConfiguration() { |
||
109 | return [ |
||
110 | 'settings' => array_diff_key( |
||
111 | $this->configuration, |
||
112 | ['entity_browser_id' => 0] |
||
113 | ), |
||
114 | 'uuid' => $this->uuid(), |
||
115 | 'weight' => $this->getWeight(), |
||
116 | 'label' => $this->label(), |
||
117 | 'id' => $this->id(), |
||
118 | ]; |
||
119 | } |
||
120 | |||
121 | /** |
||
122 | * {@inheritdoc} |
||
123 | */ |
||
124 | public function setConfiguration(array $configuration) { |
||
139 | |||
140 | /** |
||
141 | * {@inheritdoc} |
||
142 | */ |
||
143 | public function calculateDependencies() { |
||
146 | |||
147 | /** |
||
148 | * {@inheritdoc} |
||
149 | */ |
||
150 | public function id() { |
||
153 | |||
154 | /** |
||
155 | * {@inheritdoc} |
||
156 | */ |
||
157 | public function uuid() { |
||
160 | |||
161 | /** |
||
162 | * {@inheritdoc} |
||
163 | */ |
||
164 | public function label() { |
||
167 | |||
168 | /** |
||
169 | * {@inheritdoc} |
||
170 | */ |
||
171 | public function setLabel($label) { |
||
175 | |||
176 | /** |
||
177 | * {@inheritdoc} |
||
178 | */ |
||
179 | public function getWeight() { |
||
182 | |||
183 | /** |
||
184 | * {@inheritdoc} |
||
185 | */ |
||
186 | public function setWeight($weight) { |
||
190 | |||
191 | /** |
||
192 | * {@inheritdoc} |
||
193 | */ |
||
194 | public function validate(array &$form, FormStateInterface $form_state) {} |
||
195 | |||
196 | /** |
||
197 | * {@inheritdoc} |
||
198 | */ |
||
199 | public function submit(array &$element, array &$form, FormStateInterface $form_state) {} |
||
200 | |||
201 | /** |
||
202 | * Dispatches event that informs all subscribers about new selected entities. |
||
203 | * |
||
204 | * @param array $entities |
||
205 | * Array of entities. |
||
206 | */ |
||
207 | protected function selectEntities(array $entities, FormStateInterface $form_state) { |
||
219 | } |
||
220 |