public function SuggestionEditForm::buildForm in Autocomplete Search Suggestions 8
Same name and namespace in other branches
- 8.2 src/Form/SuggestionEditForm.php \Drupal\suggestion\Form\SuggestionEditForm::buildForm()
- 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\FormCode
public function buildForm(array $form, FormStateInterface $form_state, $ngram = '') {
if (!$ngram) {
return $form;
}
$obj = SuggestionStorage::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' => SuggestionStorage::getSrcOptions(),
'#default_value' => SuggestionHelper::srcBits($obj->src),
'#multiple' => TRUE,
'#required' => TRUE,
'#weight' => 50,
];
$form['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Submit'),
'#weight' => 100,
];
return $form;
}