function QueueExampleForm::submitShowQueue
Same name in other branches
- 8.x-1.x queue_example/src/Forms/QueueExampleForm.php \Drupal\queue_example\Forms\QueueExampleForm::submitShowQueue()
- 4.0.x modules/queue_example/src/Form/QueueExampleForm.php \Drupal\queue_example\Form\QueueExampleForm::submitShowQueue()
Submit function for the show-queue button.
Parameters
array $form: Form definition array.
\Drupal\Core\Form\FormStateInterface $form_state: Form state object.
File
-
modules/
queue_example/ src/ Form/ QueueExampleForm.php, line 272
Class
- QueueExampleForm
- Form with examples on how to use queue.
Namespace
Drupal\queue_example\FormCode
public function submitShowQueue(array &$form, FormStateInterface $form_state) {
$queue = $this->queueFactory
->get($form_state->getValue('queue_name'));
// There is no harm in trying to recreate existing.
$queue->createQueue();
// Get the number of items.
$count = $queue->numberOfItems();
// Update the form item counter.
$form_state->set('insert_counter', $count + 1);
// Unset the string_to_add textbox.
$form_state->unsetValue('string_to_add');
$form_state->setRebuild();
}