You are here

public static function ChangeSyncForm::finishBatch in Demonstration site (Sandbox / Snapshot) 8

Finish batch.

This function is a static function to avoid serializing the ConfigSync object unnecessarily.

File

src/Form/ChangeSyncForm.php, line 395

Class

ChangeSyncForm
Construct the storage changes in a configuration synchronization form.

Namespace

Drupal\demo\Form

Code

public static function finishBatch($success, $results, $operations) {
  if ($success) {
    if (!empty($results['errors'])) {
      foreach ($results['errors'] as $error) {
        \Drupal::messenger()
          ->addMessage($error, 'error');
        \Drupal::logger('config_sync')
          ->error($error);
      }
      \Drupal::messenger()
        ->addMessage(\Drupal::translation()
        ->translate('The configuration was imported with errors.'), 'warning');
    }
    else {
      \Drupal::messenger()
        ->addMessage(\Drupal::translation()
        ->translate('The configuration was imported successfully.'));
    }
  }
  else {

    // An error occurred.
    // $operations contains the operations that remained unprocessed.
    $error_operation = reset($operations);
    $message = \Drupal::translation()
      ->translate('An error occurred while processing %error_operation with arguments: @arguments', [
      '%error_operation' => $error_operation[0],
      '@arguments' => print_r($error_operation[1], TRUE),
    ]);
    \Drupal::messenger()
      ->addMessage($message, 'error');
  }
}