1

I have a module with batch operations, this is my hook_menu

$items['some-pretty-url'] = array(
    'title'            => 'Title',
    'page callback'    => 'drupal_get_form',
    'page arguments'   => array('import_form'),
    'access arguments' => array('access content'),
    'type'             => MENU_NORMAL_ITEM,
);

...and this is my batch config

$batch  = array(
    'title'            => t('Lorem ipsum Elit pariatur Duis et elit aute.'),
    'init_message'     => t('Commencing...'),
    'operations'       => $operations,
    'progress_message' => t('Processed: @current out of @total.'),
    'error_message'    => t('An error occurred during processing.'),
    'finished'         => '_import_finished',
);

Batch works pretty good if I have the module definition in the .module file, but if I move the functions to another file the batch simply does not work at all.

$items['some-pretty-url'] = array(
    'title'            => 'Title',
    'page callback'    => 'drupal_get_form',
    'page arguments'   => array('import_form'),
    'access arguments' => array('access content'),
    'type'             => MENU_NORMAL_ITEM,
    'file'             => 'module_definition.inc', //move module to another file
);

$batch  = array(
    'title'            => t('Lorem ipsum Elit pariatur Duis et elit aute.'),
    'init_message'     => t('Commencing...'),
    'operations'       => $operations,
    'progress_message' => t('Processed: @current out of @total.'),
    'error_message'    => t('An error occurred during processing.'),
    'finished'         => '_import_finished',
    'file'             => 'module_definition.inc', //batch functions are here
);

Batch function is not being called even if I set the file argument in the batch configuration.

  • Have you checked by clearing cache? – DRUPWAY Sep 2 '14 at 5:02
  • 3 times, @Clive has a very usefull answer – a77icu5 Sep 2 '14 at 20:56
1

When you run a batch the URL automatically changes to /batch...at that path, Drupal doesn't know to include your module_definition.inc file. It'll only process the menu hook when the path is 'some-pretty-url', so module_definition.inc will only be included then.

If you move your batch definition into the module file it'll start working, and the file you've told the batch system to find the processing function in will be included as you'd expect, because now Drupal knows it needs to be included.

  • yeah, I have everything in the module file, I just wanted to create a different file for the logic, really usefull answer ! – a77icu5 Sep 2 '14 at 20:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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