You are here

public function DeleteTermsForm::buildForm in Taxonomy Manager 2.0.x

Same name and namespace in other branches
  1. 8 src/Form/DeleteTermsForm.php \Drupal\taxonomy_manager\Form\DeleteTermsForm::buildForm()

Form constructor.

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 The form structure.

Overrides FormInterface::buildForm

File

src/Form/DeleteTermsForm.php, line 57

Class

DeleteTermsForm
Form for deleting given terms.

Namespace

Drupal\taxonomy_manager\Form

Code

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 delete.'),
    ];
    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 ($selected_terms as $t) {
    $term = $this->termStorage
      ->load($t);
    $items[] = $term
      ->getName();
    $form['selected_terms'][$t] = [
      '#type' => 'value',
      '#value' => $t,
    ];
  }
  $form['terms'] = [
    '#theme' => 'item_list',
    '#items' => $items,
    '#title' => $this
      ->t('Selected terms for deletion:'),
  ];
  $form['delete_orphans'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Delete children of selected terms, if there are any'),
  ];
  $form['delete'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Delete'),
  ];
  return $form;
}