queue_example_add_remove_form_insert

7 queue_example.module queue_example_add_remove_form_insert($form, &$form_state)
8 queue_example.module queue_example_add_remove_form_insert($form, &$form_state)

Submit function for the insert-into-queue button.

Related topics

1 string reference to 'queue_example_add_remove_form_insert'

File

queue_example/queue_example.module, line 139
Examples demonstrating the Drupal Queue API.

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']);
  $queue->createQueue(); // There is no harm in trying to recreate existing.

  // 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'])));
  $form_state['rebuild'] = TRUE; // Allows us to keep information in $form_state.
  // 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']++;
}
Login or register to post comments