How to solve claimitem() in batch process?
-
29-09-2020 - |
Question
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);
}
}
I am getting error like this. Any help will be appreciable Thanks.
Solution
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',
);
Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange