You are here

public function QueueExampleForm::submitShowQueue in Examples for Developers 8

Submit function for the show-queue button.

Parameters

array $form: Form definition array.

\Drupal\Core\Form\FormStateInterface $form_state: Form state object.

File

queue_example/src/Forms/QueueExampleForm.php, line 272

Class

QueueExampleForm
Form with examples on how to use queue.

Namespace

Drupal\queue_example\Forms

Code

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();
}