function queue_example_add_remove_form_claim

Submit function for the "claim" button.

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

Related topics

1 string reference to 'queue_example_add_remove_form_claim'
queue_example_add_remove_form in queue_example/queue_example.module
Form generator for managing the queue.

File

queue_example/queue_example.module, line 200

Code

function queue_example_add_remove_form_claim($form, &$form_state) {
    $queue = DrupalQueue::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)) {
        drupal_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 {
        drupal_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;
}