You are here

public function SynonymImportForm::validateForm in Search API Synonym 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/SynonymImportForm.php, line 180

Class

SynonymImportForm
Class SynonymImportForm.

Namespace

Drupal\search_api_synonym\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  parent::validateForm($form, $form_state);
  $values = $form_state
    ->getValues();

  // Get plugin instance for active plugin.
  $instance_active = $this
    ->getPluginInstance($values['plugin']);

  // Validate the uploaded file.
  $extensions = $instance_active
    ->allowedExtensions();
  $validators = [
    'file_validate_extensions' => $extensions,
  ];
  $file = file_save_upload('file_upload', $validators, FALSE, 0, FileSystemInterface::EXISTS_RENAME);
  if (isset($file)) {
    if ($file) {
      $form_state
        ->setValue('file_upload', $file);
    }
    else {
      $form_state
        ->setErrorByName('file_upload', $this
        ->t('The import file could not be uploaded.'));
    }
  }

  // Call the form validation handler for each of the plugins.
  foreach ($this->availablePlugins as $instance) {
    $instance
      ->validateConfigurationForm($form, $form_state);
  }
}