function queue_example_add_remove_form_insert

Submit function for the insert-into-queue button.

Related topics

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

File

queue_example/queue_example.module, line 155

Code

function queue_example_add_remove_form_insert($form, &$form_state) {
    // Get a queue (of the default type) called 'queue_example_queue'.
    // If the default queue class is SystemQueue this creates a queue that stores
    // its items in the database.
    $queue = DrupalQueue::get($form_state['values']['queue_name']);
    // There is no harm in trying to recreate existing.
    $queue->createQueue();
    // Queue the string.
    $queue->createItem($form_state['values']['string_to_add']);
    $count = $queue->numberOfItems();
    drupal_set_message(t('Queued your string (@string_to_add). There are now @count items in the queue.', array(
        '@count' => $count,
        '@string_to_add' => $form_state['values']['string_to_add'],
    )));
    // Setting 'rebuild' to TRUE allows us to keep information in $form_state.
    $form_state['rebuild'] = TRUE;
    // Unsetting the string_to_add allows us to set the incremented default value
    // for the user so they don't have to type anything.
    unset($form_state['input']['string_to_add']);
    $form_state['storage']['insert_counter']++;
}