You are here

public function SuggestionEditForm::buildForm in Autocomplete Search Suggestions 8.2

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

The suggestion edit form.

Parameters

array $form: A drupal form array.

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

string $ngram: The ngram that is being edited.

Return value

array A Drupal form array.

Overrides FormInterface::buildForm

File

src/Form/SuggestionEditForm.php, line 28

Class

SuggestionEditForm
Suggestion indexing form.

Namespace

Drupal\suggestion\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $ngram = '') {
  if (!$ngram) {
    return $form;
  }
  $obj = Storage::getSuggestion($ngram);
  $form['ngram'] = [
    '#type' => 'value',
    '#value' => $obj->ngram,
  ];
  $form['atoms'] = [
    '#type' => 'value',
    '#value' => $obj->atoms,
  ];
  $form['density'] = [
    '#type' => 'value',
    '#value' => $obj->density,
  ];
  $form['ngram_txt'] = [
    '#markup' => $this
      ->t('Suggestion: @ngram', [
      '@ngram' => $obj->ngram,
    ]),
    '#suffix' => '<br />',
    '#weight' => 10,
  ];
  $form['atoms_txt'] = [
    '#markup' => $this
      ->t('Words: @atoms', [
      '@atoms' => $obj->atoms,
    ]),
    '#suffix' => '<br />',
    '#weight' => 20,
  ];
  $form['density_txt'] = [
    '#markup' => $this
      ->t('Score: @density', [
      '@density' => $obj->density,
    ]),
    '#weight' => 30,
  ];
  $form['qty'] = [
    '#title' => $this
      ->t('Quantity'),
    '#type' => 'textfield',
    '#default_value' => $obj->qty,
    '#required' => TRUE,
    '#weight' => 40,
  ];
  $form['src'] = [
    '#title' => $this
      ->t('Source'),
    '#type' => 'select',
    '#options' => Storage::getSrcOptions(),
    '#default_value' => Helper::srcBits($obj->src),
    '#multiple' => TRUE,
    '#required' => TRUE,
    '#weight' => 50,
  ];
  $form['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Submit'),
    '#weight' => 100,
  ];
  return $form;
}