3 namespace Drupal\entity_browser\Plugin\EntityBrowser\WidgetSelector;
5 use Drupal\entity_browser\WidgetSelectorBase;
6 use Drupal\Core\Form\FormStateInterface;
9 * Displays widgets in a select list.
11 * @EntityBrowserWidgetSelector(
13 * label = @Translation("Drop down widget"),
14 * description = @Translation("Displays the widgets in a drop down.")
17 class DropDown extends WidgetSelectorBase {
22 public function getForm(array &$form = [], FormStateInterface &$form_state = NULL) {
23 // Set a wrapper container for us to replace the form on ajax call.
24 $form['#prefix'] = '<div id="entity-browser-form">';
25 $form['#suffix'] = '</div>';
27 $element['widget'] = [
29 '#options' => $this->widget_ids,
30 '#default_value' => $this->getDefaultWidget(),
31 '#executes_submit_callback' => TRUE,
32 '#limit_validation_errors' => [['widget']],
33 // #limit_validation_errors only takes effect if #submit is present.
36 'callback' => [$this, 'changeWidgetCallback'],
37 'wrapper' => 'entity-browser-form',
41 $element['change'] = [
44 '#value' => $this->t('Change'),
45 '#attributes' => ['class' => ['js-hide']],
54 public function submit(array &$form, FormStateInterface $form_state) {
55 return $form_state->getValue('widget');
59 * AJAX callback to refresh form.
63 * @param FormStateInterface $form_state
67 * Form element to replace.
69 public function changeWidgetCallback(array &$form, FormStateInterface $form_state) {