You are here

public function ContentImport::validateForm in Content Import 8.9

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/ContentImport.php, line 102

Class

ContentImport
Configure Content Import settings for this site.

Namespace

Drupal\contentimport\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $form_values = $form_state
    ->getValues();
  if ($form_values['contentimport_contenttype'] == 'none' || $form_values['contentimport_importtype'] == 0) {
    $form_state
      ->setErrorByName('contentimport_contenttype', $this
      ->t('Content type or Import type missing. Please select.'));
  }
  else {
    $this->file = file_save_upload('file_upload', $form['file_upload']['#upload_validators'], FALSE, 0);
    if (!$this->file) {
      $form_state
        ->setErrorByName('file_upload', $this
        ->t('Provided file is not a CSV file or is corrupted.'));
    }
  }
}