1 batch_example.module batch_example_simple_form()

Form builder function to allow choice of which batch to run.

Related topics


modules/examples/batch_example/batch_example.module, line 47
Hook implementations for the Batch Example module.


function batch_example_simple_form() {
  $form['description'] = array(
    '#type' => 'markup',
    '#markup' => t('This example offers two different batches. The first does 1000 identical operations, each completed in one run; the second does 20 operations, but each takes more than one run to operate if there are more than 5 nodes.'),
  $form['batch'] = array(
    '#type' => 'select',
    '#title' => 'Choose batch',
    '#options' => array(
      'batch_1' => t('batch 1 - 1000 operations, each loading the same node'),
      'batch_2' => t('batch 2 - 20 operations. each one loads all nodes 5 at a time'),
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Go',

  // If no nodes, prevent submission.
  // Find out if we have a node to work with. Otherwise it won't work.
  $nid = batch_example_lowest_nid();
  if (empty($nid)) {
    backdrop_set_message(t("You don't currently have any nodes, and this example requires a node to work with. As a result, this form is disabled."));
    $form['submit']['#disabled'] = TRUE;
  return $form;