You are here

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

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/ExportTermsMiniForm.php, line 45

Class

ExportTermsMiniForm
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 = []) {
  $form['voc'] = [
    '#type' => 'value',
    '#value' => $taxonomy_vocabulary,
  ];
  $form['selected_terms']['#tree'] = TRUE;

  // Load tree.
  $tree = $this->termStorage
    ->loadTree($taxonomy_vocabulary
    ->id());
  $result = [];
  foreach ($tree as $term) {
    $result[] = str_repeat('-', $term->depth) . $term->name;
  }
  $desc = 'Term names with hierarchy: Only term names are exported. Child terms are prefixed with dashes.';
  $desccsv = 'CSV: The comma-separated-values export has following columns: voc id | term id | term name | description | parent id 1 | ... | parent id n';
  $form['exported_data'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Exported data'),
    '#default_value' => implode("\n", $result),
    '#rows' => 12,
    '#prefix' => '<div id="export-wrapper">',
    '#suffix' => '</div>',
    '#description' => $desc,
  ];
  return $form;
}