You are here

public function BackupMigrateAdvancedBackupForm::validateForm in Backup and Migrate 5.0.x

Same name and namespace in other branches
  1. 8.4 src/Form/BackupMigrateAdvancedBackupForm.php \Drupal\backup_migrate\Form\BackupMigrateAdvancedBackupForm::validateForm()

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/BackupMigrateAdvancedBackupForm.php, line 88

Class

BackupMigrateAdvancedBackupForm
Provides a form for performing a 1-click site backup.

Namespace

Drupal\backup_migrate\Form

Code

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

  // Let the plugins validate their own config data.
  if ($plugin_errors = $bam
    ->plugins()
    ->map('configErrors', [
    'operation' => 'backup',
  ])) {
    $has_token_module = \Drupal::moduleHandler()
      ->moduleExists('token');
    foreach ($plugin_errors as $plugin_key => $errors) {
      if ($plugin_key == "namer" && isset($errors[0])) {
        if ($errors[0]
          ->getFieldKey() == "filename" && $has_token_module) {
          continue;
        }
      }
      foreach ($errors as $error) {
        $form_state
          ->setErrorByName($plugin_key . '][' . $error
          ->getFieldKey(), $this
          ->t($error
          ->getMessage(), $error
          ->getReplacement()));
      }
    }
  }
}