-1

I'm trying to create a batch process in Drupal 8, but I'm getting the following error:

Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'logs_export_data' not found or invalid function name in _batch_process() (line 252 of /var/www/recotool/core/includes/batch.inc).

This is my code:

public function batch_logs() {

$batch = array(
  'title' => t('Logs Export'),
  'operations' => array(
    array('logs_export_data', array($_GET['id']))
  ),
  'finished' => 'log_export_data_finish',
  'file' => drupal_get_path('module', 'example') ./src/ManualImportController',
);
batch_set($batch);
return batch_process('logs-example');
}

public function logs_export_data($value, &$context) {

print_r($value);exit;

}

What am I doing wrong?

closed as off-topic by kiamlaluno Jun 14 '15 at 6:25

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions on programming, PHP, SQL, etc. that do not relate directly to Drupal are off-topic here, but can be asked on Stack Overflow." – kiamlaluno
If this question can be reworded to fit the rules in the help center, please edit the question.

  • This is a plain PHP function: You cannot pass 'logs_export_data' to call_user_func_array() when logs_export_data() is an object method. Once you get the error message, and see the documentation for call_user_func_array(), you should understand what the correct code is. Drupal doesn't change the way call_user_func_array() works, and that is a PHP function. – kiamlaluno Jun 14 '15 at 6:25
2

Your function is in a controller/class (or it could not be public), but you're trying to call it as a function. That can't work.

You can either make your method static and define the callback as 'class::method', or make it a function, not a method.

  • Will you please give relevant example. I am new to drupal8. – Ajay Reddy Jun 3 '15 at 14:34
  • It is possible to pass a method in the batch operations, just pass an array containing $this and your method: 'operations' => [$this, 'myMethod']. – Gun5m0k3 Jul 13 '17 at 14:30

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