You are here

public function WebformAutocomplete::form in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Plugin/WebformElement/WebformAutocomplete.php \Drupal\webform\Plugin\WebformElement\WebformAutocomplete::form()

Gets the actual configuration webform array to be built.

Parameters

array $form: An associative array containing the structure of the form.

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

Return value

array An associative array contain the element's configuration webform without any default values.

Overrides TextBase::form

File

src/Plugin/WebformElement/WebformAutocomplete.php, line 71

Class

WebformAutocomplete
Provides a 'autocomplete' element.

Namespace

Drupal\webform\Plugin\WebformElement

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);
  $form['autocomplete'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Autocomplete settings'),
  ];
  $form['autocomplete']['autocomplete_items'] = [
    '#type' => 'webform_element_options',
    '#custom__type' => 'webform_multiple',
    '#title' => $this
      ->t('Autocomplete values'),
  ];
  $form['autocomplete']['autocomplete_existing'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Include existing submission values'),
    '#description' => $this
      ->t("If checked, all existing submission values will be visible to the webform's users."),
    '#return_value' => TRUE,
  ];
  $form['autocomplete']['autocomplete_limit'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Autocomplete limit'),
    '#description' => $this
      ->t("The maximum number of matches to be displayed."),
    '#min' => 1,
  ];
  $form['autocomplete']['autocomplete_match'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Autocomplete minimum number of characters'),
    '#description' => $this
      ->t('The minimum number of characters a user must type before a search is performed.'),
    '#min' => 1,
  ];
  $form['autocomplete']['autocomplete_match_operator'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Autocomplete matching operator'),
    '#description' => $this
      ->t('Select the method used to collect autocomplete suggestions.'),
    '#options' => [
      'STARTS_WITH' => $this
        ->t('Starts with'),
      'CONTAINS' => $this
        ->t('Contains'),
    ],
  ];
  return $form;
}