You are here

function gathercontent_upload_finished in GatherContent 8.5

Same name and namespace in other branches
  1. 8.3 gathercontent.module \gathercontent_upload_finished()
  2. 7.3 gathercontent.module \gathercontent_upload_finished()

Finished callback.

@inheritdoc

1 string reference to 'gathercontent_upload_finished'
ContentUploadSelectForm::submitForm in gathercontent_upload_ui/src/Form/ContentUploadSelectForm.php
Form submission handler.

File

gathercontent_upload_ui/gathercontent_upload_ui.module, line 13
GatherContent Upload UI.

Code

function gathercontent_upload_finished($success, $results, $operations) {
  $messenger = \Drupal::messenger();
  if ($success) {
    if ($results['success'] > 0) {
      $messenger
        ->addStatus(\Drupal::translation()
        ->formatPlural($results['success'], '1 item was uploaded successfully.', '@count items were uploaded successfully.'));
    }
    if ($results['failed'] > 0) {
      $messenger
        ->addError(\Drupal::translation()
        ->formatPlural($results['failed'], '1 item could not be uploaded. Check errors below.', '@count items could not be uploaded. Check errors below.'));
    }
    if ($results['failed'] == 0 && $results['success'] == 0) {
      $messenger
        ->addStatus(t('Nothing was uploaded.'));
    }
    if (isset($results['messages']) && count($results['messages']) > 0) {
      foreach ($results['messages'] as $message) {
        $messenger
          ->addError($message);
      }
    }
  }
  else {
    $error_operation = reset($operations);
    $messenger
      ->addError(t('An error occurred while processing @operation with arguments : @args', [
      '@operation' => $error_operation[0],
      '@args' => print_r($error_operation[0], TRUE),
    ]));
  }
  return TRUE;
}