0

I am doing batch process in D8. here is my code: This code is in Controller.php

$batch = array(
          'title' => t('Started Importing node Data.'),
          'error_message' => t('Error!'), //Error Message
          'finished' => 'node_data_import_batch_finished',
        );
        $count_nodes = '';
        $j = 0;
        $data_chunk = array_chunk($csv, 100);
        foreach ($data_chunk as $node_created) {
          $count_nodes += count($node_created);
          $batch['operations'][] = array('node_data_import_batch', array($node_created,  $keys));
          $j++;
        }
        batch_set($batch);

And callback function is in .module

function node_data_import_batch($node_created,  $keys){
//Code here
}

function node_data_import_batch_finished($success, $results, $operations){
 if ($success) {
    $message = "Batch Process Successfully executed for Node Data.";
    drupal_set_message($message);
  }
}

enter image description here

I am getting error like this. Any help will be appreciable Thanks.

1 Answer 1

0

Add the 'file' key in your batch:

  • file: Path to the file containing the definitions of the 'operations' and 'finished' functions, for instance if they don't reside in the main .module file. The path should be relative to base_path(), and thus should be built using drupal_get_path().
$batch = array(
  'title' => t('Started Importing node Data.'),
  'error_message' => t('Error!'), //Error Message
  'finished' => 'node_data_import_batch_finished',
  'file' => drupal_get_path('module', 'YOUR_MODULE_NAME') . '/YOUR_MODULE_NAME.module',
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.