You are here

public function Select2Widget::settingsForm in Select 2 8

Returns a form to configure settings for the widget.

Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the widget. The field_ui module takes care of handling submitted form values.

Parameters

array $form: The form where the settings form is being included in.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form definition for the widget settings.

Overrides WidgetBase::settingsForm

1 call to Select2Widget::settingsForm()
Select2EntityReferenceWidget::settingsForm in src/Plugin/Field/FieldWidget/Select2EntityReferenceWidget.php
Returns a form to configure settings for the widget.
1 method overrides Select2Widget::settingsForm()
Select2EntityReferenceWidget::settingsForm in src/Plugin/Field/FieldWidget/Select2EntityReferenceWidget.php
Returns a form to configure settings for the widget.

File

src/Plugin/Field/FieldWidget/Select2Widget.php, line 37

Class

Select2Widget
Plugin implementation of the 'select2' widget.

Namespace

Drupal\select2\Plugin\Field\FieldWidget

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $element['width'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Field width'),
    '#default_value' => $this
      ->getSetting('width'),
    '#description' => $this
      ->t("Define a width for the select2 field. It can be either 'element', 'computedstyle', 'style', 'resolve' or any possible CSS value. E.g. 500px, 50%, 200em. See the <a href='https://select2.org/appearance#container-width'>select2 documentation</a> for further explanations."),
    '#required' => TRUE,
    '#size' => '12',
    '#pattern' => "([0-9]*\\.[0-9]+|[0-9]+)(cm|mm|in|px|pt|pc|em|ex|ch|rem|vm|vh|vmin|vmax|%)|element|computedstyle|style|resolve|auto|initial|inherit",
  ];
  return $element;
}