You are here

public function TaxonomyImporterForm::submitForm in Hierarchical Taxonomy Import 8

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormInterface::submitForm

File

src/Form/TaxonomyImporterForm.php, line 119

Class

TaxonomyImporterForm
Class TaxonomyImporterForm.

Namespace

Drupal\hierarchical_taxonomy_importer\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $csv_file_path = $form_state
    ->getValue('csv_file');
  if (($handle = fopen($csv_file_path, "r")) !== FALSE) {

    // taxonomy_' . time();
    $vid = $form_state
      ->getValue('vocabulary');
    $output = [];
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
      $output[] = $data;
    }
    $result = $this->hierarchicalTaxonomyImporter
      ->import($vid, $output);
  }
  drupal_set_message(t('All terms have been imported successfully.'));
}