1 queue_example.module queue_example_add_remove_form_claim($form, &$form_state)

Submit function for the "claim" button.

Claims (retrieves) an item from the queue and reports the results.

Related topics

File

modules/examples/queue_example/queue_example.module, line 197
Hook implementations for the Queue Example module.

Code

function queue_example_add_remove_form_claim($form, &$form_state) {
  $queue = BackdropQueue::get($form_state['values']['queue_name']);
  // There is no harm in trying to recreate existing.
  $queue->createQueue();
  $item = $queue->claimItem($form_state['values']['claim_time']);
  $count = $queue->numberOfItems();
  if (!empty($item)) {
    backdrop_set_message(
    t('Claimed item id=@item_id string=@string for @seconds seconds. There are @count items in the queue.', 
    array(
      '@count' => $count,
      '@item_id' => $item->item_id,
      '@string' => $item->data,
      '@seconds' => $form_state['values']['claim_time'],
    )
    )
    );
  }
  else {
    backdrop_set_message(t('There were no items in the queue available to claim. There are @count items in the queue.', array('@count' => $count)));
  }
  $form_state['rebuild'] = TRUE;
}