You are here

public function YamlFormAutocomplete::form in YAML Form 8

Gets the actual configuration form 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 form without any default values..

Overrides TextBase::form

File

src/Plugin/YamlFormElement/YamlFormAutocomplete.php, line 63

Class

YamlFormAutocomplete
Provides a 'autocomplete' element.

Namespace

Drupal\yamlform\Plugin\YamlFormElement

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' => 'yamlform_element_options',
    '#custom__type' => 'yamlform_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 form'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;
}