You are here

public function TaxonomyImporterForm::validateForm in Hierarchical Taxonomy Import 8

Form validation 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 FormBase::validateForm

File

src/Form/TaxonomyImporterForm.php, line 100

Class

TaxonomyImporterForm
Class TaxonomyImporterForm.

Namespace

Drupal\hierarchical_taxonomy_importer\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  parent::validateForm($form, $form_state);

  // Getting file array.
  $files = $this
    ->getRequest()->files
    ->get('files', []);

  // Checking if file is uploaded.
  if (!empty($files['csv_file'])) {
    $file_upload = $files['csv_file'];
    if ($file_upload
      ->isValid()) {
      $form_state
        ->setValue('csv_file', $file_upload
        ->getRealPath());
      return;
    }
  }
  $form_state
    ->setErrorByName('csv_file', $this
    ->t('The file could not be uploaded.'));
}