You are here

function batch_example_simple_form in Examples for Developers 7

Same name and namespace in other branches
  1. 6 batch_example/batch_example.module \batch_example_simple_form()

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

Related topics

1 string reference to 'batch_example_simple_form'
batch_example_menu in batch_example/batch_example.module
Implements hook_menu().

File

batch_example/batch_example.module, line 49
Outlines how a module can use the Batch API.

Code

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 on 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)) {
    drupal_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;
}