You are here

public function ExportTermsForm::buildForm in Taxonomy Manager 8

Same name and namespace in other branches
  1. 2.0.x src/Form/ExportTermsForm.php \Drupal\taxonomy_manager\Form\ExportTermsForm::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/ExportTermsForm.php, line 45

Class

ExportTermsForm
Form for exporting 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 export.'),
    ];
    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 export:'),
  ];
  $form['download_csv'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Download CSV'),
  ];
  $form['export'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Export'),
  ];
  return $form;
}