You are here

public static function NodeExport::nodeExportFinishedCallback in Node export 8

Batch finish callback method. Handles results & display messages to user.

Parameters

bool $success: Whether or not any fatal PHP errors were detected.

array $results: An array containing the results key of context array.

array $operations: An array containing batch operations.

File

src/NodeExport.php, line 107

Class

NodeExport
Provides a Node Export function.

Namespace

Drupal\node_export

Code

public static function nodeExportFinishedCallback($success, array $results, array $operations) {

  // The 'success' parameter means no fatal PHP errors were detected. All
  // other error management should be handled using 'results'.
  if ($success) {
    $message = \Drupal::translation()
      ->formatPlural(count($results), 'One node exported ', '@count nodes exported ');
  }
  else {
    $message = $this
      ->t('Finished with an error.');
  }
  $file = NodeExport::export($results, 'json', TRUE);
  if ($file) {
    $message = $message . ' to ' . \Drupal::service('file_system')
      ->realpath($file
      ->getFileUri());
    \Drupal::messenger()
      ->addStatus($message);
  }
}