You are here

public function Select2Widget::buildConfigurationForm in Select 2 8

Provides a configuration form for this widget.

Parameters

array $form: A form API form array.

\Drupal\Core\Form\FormStateInterface $form_state: The form state object.

\Drupal\facets\FacetInterface $facet: The facet entitu.

Return value

array A renderable form array.

Overrides WidgetPluginBase::buildConfigurationForm

File

modules/select2_facets/src/Plugin/facets/widget/Select2Widget.php, line 135

Class

Select2Widget
The select2 widget.

Namespace

Drupal\select2_facets\Plugin\facets\widget

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state, FacetInterface $facet) {
  $form = parent::buildConfigurationForm($form, $form_state, $facet);
  $form['width'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Field width'),
    '#default_value' => $this
      ->getConfiguration()['width'],
    '#description' => $this
      ->t("Define a width for the select2 field. It can be either 'element', 'computedstyle', 'style', 'resolve' or any possible CSS unit. 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",
  ];
  $form['autocomplete'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Autocomplete'),
    '#default_value' => $this
      ->getConfiguration()['autocomplete'],
    '#description' => $this
      ->t('Options will be lazy loaded. This is recommended for lists with a lot of values.'),
  ];
  $form['match_operator'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Autocomplete matching'),
    '#default_value' => $this
      ->getConfiguration()['match_operator'],
    '#options' => $this
      ->getMatchOperatorOptions(),
    '#description' => $this
      ->t('Select the method used to collect autocomplete suggestions. Note that <em>Contains</em> can cause performance issues on sites with thousands of entities.'),
    '#states' => [
      'visible' => [
        ':input[name$="widget_config[autocomplete]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  return $form;
}