public function MoveTermsForm::buildForm in Taxonomy Manager 8
Same name and namespace in other branches
- 2.0.x src/Form/MoveTermsForm.php \Drupal\taxonomy_manager\Form\MoveTermsForm::buildForm()
@TODO: Add autocomplete to select/add parent term.
Overrides FormInterface::buildForm
File
- src/
Form/ MoveTermsForm.php, line 47
Class
- MoveTermsForm
- Form for deleting given terms.
Namespace
Drupal\taxonomy_manager\FormCode
public function buildForm(array $form, FormStateInterface $form_state, VocabularyInterface $taxonomy_vocabulary = NULL, $selected_terms = []) {
if (empty($selected_terms)) {
$form['info'] = [
'#markup' => $this
->t('Please select the terms you want to move.'),
];
return $form;
}
// Cache form state so that we keep the parents in the modal dialog.
$form_state
->setCached(TRUE);
$form['voc'] = [
'#type' => 'value',
'#value' => $taxonomy_vocabulary,
];
$form['selected_terms']['#tree'] = TRUE;
$items = [];
foreach ($this->termStorage
->loadMultiple($selected_terms) as $term) {
$items[] = $term
->label();
$form['selected_terms'][$term
->id()] = [
'#type' => 'value',
'#value' => $term
->id(),
];
}
$form['terms'] = [
'#theme' => 'item_list',
'#items' => $items,
'#title' => $this
->t('Selected terms to move:'),
];
$form['keep_old_parents'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Keep old parents and add new ones (multi-parent). Otherwise old parents get replaced.'),
];
$form['delete'] = [
'#type' => 'submit',
'#value' => $this
->t('Move'),
];
return $form;
}