You are here

public static function MetatagImport::importFinish in Metatag Import Export CSV 8

Batch finished callback for import.

File

src/MetatagImport.php, line 223

Class

MetatagImport
Class for batch process for metatag import.

Namespace

Drupal\metatag_import_export_csv

Code

public static function importFinish($success, $results, $operations) {
  $messenger = \Drupal::messenger();
  if ($success) {
    $message_entity_summary = [];
    foreach ($results['success'] as $entity_type => $entity_ids) {
      $entity_type_definition = \Drupal::service('entity_type.manager')
        ->getDefinition($entity_type);
      $message_entity_summary[] = \Drupal::service('string_translation')
        ->formatPlural(count($entity_ids), '1 ' . $entity_type_definition
        ->getSingularLabel(), '@count ' . $entity_type_definition
        ->getPluralLabel());
    }
    if ($message_entity_summary) {
      $messenger
        ->addMessage(t('Successfully updated entities: @summary.', [
        '@summary' => implode(', ', $message_entity_summary),
      ]));
    }
    foreach ($results['error'] as $error_message) {
      $messenger
        ->addError($error_message);
    }
  }
  else {
    $error_operation = reset($operations);
    $messenger
      ->addMessage(t('An error occurred while processing @operation with arguments : @args', [
      '@operation' => $error_operation[0],
      '@args' => print_r($error_operation[0], TRUE),
    ]), 'error');
  }
}