Version 1
[yaffs-website] / web / modules / contrib / entity_browser / tests / modules / entity_browser_test / src / Plugin / EntityBrowser / Widget / DummyWidget.php
1 <?php
2
3 namespace Drupal\entity_browser_test\Plugin\EntityBrowser\Widget;
4
5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\entity_browser\WidgetBase;
7
8 /**
9  * Dummy widget implementation for test purposes.
10  *
11  * @EntityBrowserWidget(
12  *   id = "dummy",
13  *   label = @Translation("Dummy widget"),
14  *   description = @Translation("Dummy widget existing for testing purposes."),
15  *   auto_select = FALSE
16  * )
17  */
18 class DummyWidget extends WidgetBase {
19
20   /**
21    * Entity to be returned.
22    *
23    * @var \Drupal\Core\Entity\EntityInterface
24    */
25   public $entity;
26
27   /**
28    * {@inheritdoc}
29    */
30   public function defaultConfiguration() {
31     return ['text' => ''] + parent::defaultConfiguration();
32   }
33
34   /**
35    * {@inheritdoc}
36    */
37   public function getForm(array &$original_form, FormStateInterface $form_state, array $additional_widget_parameters) {
38     return [
39       '#markup' => $this->configuration['text'],
40       '#parents' => [],
41     ];
42   }
43
44   /**
45    * {@inheritdoc}
46    */
47   public function submit(array &$element, array &$form, FormStateInterface $form_state) {
48     $this->selectEntities([$this->entity], $form_state);
49   }
50
51   /**
52    * {@inheritdoc}
53    */
54   protected function prepareEntities(array $form, FormStateInterface $form_state) {
55     return $form_state->getValue('dummy_entities', []);
56   }
57
58 }