You are here

public function SuggestionAdminForm::buildForm in Autocomplete Search Suggestions 3.0.x

Same name and namespace in other branches
  1. 8.2 src/Form/SuggestionAdminForm.php \Drupal\suggestion\Form\SuggestionAdminForm::buildForm()
  2. 8 src/Form/SuggestionAdminForm.php \Drupal\suggestion\Form\SuggestionAdminForm::buildForm()

The suggestion configuration form.

Parameters

array $form: A drupal form array.

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

Return value

array A Drupal form array.

Overrides FormInterface::buildForm

File

src/Form/SuggestionAdminForm.php, line 27

Class

SuggestionAdminForm
Suggestion configuration form.

Namespace

Drupal\suggestion\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $cfg = SuggestionHelper::getConfig();
  $form['entry_style'] = [
    '#title' => $this
      ->t('Entry Choices'),
    '#description' => $this
      ->t('Simple supports one autocomplete suggestion box, Advanced supports unlimited instances of autocomplete'),
    '#type' => 'radios',
    '#options' => [
      'simple' => $this
        ->t('Simple'),
      'advanced' => $this
        ->t('Advanced'),
    ],
    'advanced' => [
      '#description' => $this
        ->t('Advanced supports unlimited instances of autocomplete.'),
    ],
    'simple' => [
      '#description' => $this
        ->t('Simple supports one autocomplete suggestion box.'),
    ],
    '#default_value' => $cfg->entry_style == 'advanced' ? 'advanced' : 'simple',
    '#weight' => 0,
  ];
  $form['autocomplete'] = [
    '#title' => $this
      ->t('Form ID, field name K/V pairs'),
    '#description' => $this
      ->t('A list of colon delimited form_id and field name pairs. One pre line, (search_form:keys).'),
    '#type' => 'textarea',
    '#default_value' => $this
      ->getAutocomplete(),
    '#states' => [
      'visible' => [
        'input[name="entry_style"]' => [
          'value' => 'advanced',
        ],
      ],
    ],
    '#weight' => 10,
  ];
  $form['simple'] = [
    '#type' => 'container',
    '#tree' => FALSE,
    '#states' => [
      'visible' => [
        'input[name="entry_style"]' => [
          'value' => 'simple',
        ],
      ],
    ],
    '#weight' => 20,
  ];
  $form['simple']['form_key'] = [
    '#title' => $this
      ->t('Form ID'),
    '#type' => 'textfield',
    '#default_value' => $cfg->form_key,
  ];
  $form['simple']['field_name'] = [
    '#title' => $this
      ->t('Field Name'),
    '#type' => 'textfield',
    '#default_value' => $cfg->field_name,
  ];
  $form['min'] = [
    '#title' => $this
      ->t('Minimum Characters in a Suggestion'),
    '#type' => 'select',
    '#options' => array_combine(range(3, 10), range(3, 10)),
    '#default_value' => $cfg->min,
    '#required' => TRUE,
    '#weight' => 30,
  ];
  $form['max'] = [
    '#title' => $this
      ->t('Maximum Characters in a Suggestion'),
    '#type' => 'select',
    '#options' => array_combine(range(20, 60), range(20, 60)),
    '#default_value' => $cfg->max,
    '#required' => TRUE,
    '#weight' => 40,
  ];
  $form['atoms_min'] = [
    '#title' => $this
      ->t('Minimum Words in a Suggestion'),
    '#type' => 'select',
    '#options' => array_combine(range(1, 10), range(1, 10)),
    '#default_value' => $cfg->atoms_min,
    '#required' => TRUE,
    '#weight' => 50,
  ];
  $form['atoms_max'] = [
    '#title' => $this
      ->t('Maximum Words in a Suggestion'),
    '#type' => 'select',
    '#options' => array_combine(range(1, 10), range(1, 10)),
    '#default_value' => $cfg->atoms_max,
    '#required' => TRUE,
    '#weight' => 60,
  ];
  $form['limit'] = [
    '#title' => $this
      ->t('Maximum Suggestions Returned'),
    '#type' => 'select',
    '#options' => array_combine(range(10, 100), range(10, 100)),
    '#default_value' => $cfg->limit,
    '#required' => TRUE,
    '#weight' => 70,
  ];
  $form['types'] = [
    '#title' => $this
      ->t('Content Types'),
    '#type' => 'checkboxes',
    '#options' => $this
      ->getContentTypes(),
    '#default_value' => $cfg->types,
    '#required' => TRUE,
    '#weight' => 80,
  ];
  $form['keywords'] = [
    '#title' => $this
      ->t('Priority Suggestions'),
    '#description' => $this
      ->t('Suggestions entered here take priority.'),
    '#type' => 'textarea',
    '#default_value' => $this
      ->getKeywords(),
    '#rows' => 10,
    '#required' => FALSE,
    '#weight' => 90,
  ];
  $form['stopwords'] = [
    '#title' => $this
      ->t('Stopwords'),
    '#description' => $this
      ->t('Stopwords are not indexed.'),
    '#type' => 'textarea',
    '#default_value' => $this
      ->getStopwords(),
    '#rows' => 10,
    '#required' => FALSE,
    '#weight' => 100,
  ];
  $form['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Submit'),
    '#weight' => 110,
  ];
  return $form;
}