You are here

public function PriceListItemImportForm::validateForm in Commerce Pricelist 8.2

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/PriceListItemImportForm.php, line 203

Class

PriceListItemImportForm

Namespace

Drupal\commerce_pricelist\Form

Code

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

  /** @var \Symfony\Component\HttpFoundation\File\UploadedFile[] $all_files */
  $all_files = $this
    ->getRequest()->files
    ->get('files', []);
  if (empty($all_files['csv'])) {
    $form_state
      ->setErrorByName('csv', $this
      ->t('No CSV file was provided.'));
  }
  elseif (!$all_files['csv']
    ->isValid()) {
    $form_state
      ->setErrorByName('csv', $this
      ->t('The provided CSV file is invalid.'));
  }
}