You are here

function bibcite_import_batch_finished in Bibliography & Citation 8

Same name and namespace in other branches
  1. 2.0.x modules/bibcite_import/bibcite_import.batch.inc \bibcite_import_batch_finished()

Complete a batch process.

Parameters

bool $success: A boolean indicating whether the batch has completed successfully.

array $results: The value set in $context['results'] by callback_batch_operation().

array|bool $operations: If $success is FALSE, contains the operations that remained unprocessed.

1 string reference to 'bibcite_import_batch_finished'
ImportForm::submitForm in modules/bibcite_import/src/Form/ImportForm.php
Form submission handler.

File

modules/bibcite_import/bibcite_import.batch.inc, line 93
Batch functions.

Code

function bibcite_import_batch_finished(bool $success, array $results, $operations) {
  $messenger = \Drupal::messenger();
  if ($success) {
    if (!empty($results['success'])) {
      $message = \Drupal::translation()
        ->formatPlural(count($results['success']), 'One entity has been processed.', '@count entities have been processed.');
      $messenger
        ->addStatus($message);
    }
    else {
      $message = \Drupal::translation()
        ->translate('Entities have not been found. Please check file and format.');
      $messenger
        ->addWarning($message);
    }
  }
  else {
    $message = t('Import has been finished with an error.');
    $messenger
      ->addError($message);
  }
  if (!empty($results['errors'])) {
    $error_count_message = \Drupal::translation()
      ->formatPlural(count($results['errors']), 'One entry has not been processed:', '@count entries have not been processed:');
    $last_ten_errors = array_slice($results['errors'], -10);
    $error_message = [
      $error_count_message,
      implode("\n", $last_ten_errors),
    ];
    $messenger
      ->addError(implode("\n", $error_message));
  }
  if (!empty($results['inaccessible_entities'])) {
    $inaccessible_entities = $results['inaccessible_entities'];
    $messenger
      ->addWarning(\Drupal::translation()
      ->formatPlural($inaccessible_entities, "@count reference has not been created because you do not have the necessary permissions.", "@count references have not been created because you do not have the necessary permissions."));
  }
}