0

I have defined a batch, everything works ok, but I want to understand how the messages are displayed. So I have this batch:

$batch = array(
  'title' => t('Generate reports'),
  'operations' => array(
    array('create_report_callback', array($time_min, $time_max)),
  ),
  'init_message' => t('Starting report generation...'),
  'progress_message' => t('Generating report. Operation @current out of @total.'),
  'error_message' => t('Error detected. Please try again!'),
  'finished' => 'create_report_finished',
);

What I want to know is how to change the progress_message to something else than Operation @current out of @total. I don't know where the @current and @total come from

Thank you.

  • You can just change it to whatever you like, those are placeholders the batch processor will inject automatically if necessary. They aren't mandatory, just available – Clive Sep 24 '15 at 11:56
  • Ok, clear enough. But is it possible to have a dynamic message, with custom placeholders? Basically to generate the message inside the batch process function. – Marius Ilie Sep 24 '15 at 12:09
  • The docs suggest it's not possible without altering core: api.drupal.org/api/drupal/includes!form.inc/function/batch_set/… (search for "@current" in that page) – Clive Sep 24 '15 at 12:18
0

The placeholders @current, @total, etc are described in the file includes/form.inc in the description of the batch_set() function.

  • progress_message: Message displayed while processing the batch. Available placeholders are @current, @remaining, @total, @percentage, @estimate and @elapsed. Defaults to t('Completed @current of @total.').

You can add custom placeholders by using the t() function like this:

$my_custom_variable = 'contents of my custom variable';

$batch = array(
  'title' => t('Generate reports'),
  'operations' => array(
    array('create_report_callback', array($time_min, $time_max)),
  ),
  'init_message' => t('Starting report generation...'),
  'progress_message' => t('Generating @my_custom_placeholder report. Operation @current out of @total.', 
     array(
       '@my_custom_placeholder' => $my_custom_variable,
     )
  ),
  'error_message' => t('Error detected. Please try again!'),
  'finished' => 'create_report_finished',
);

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.