You are here

public function PushNotificationsSendMessageForm::submitForm in Push Notifications 8

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormInterface::submitForm

File

src/Form/PushNotificationsSendMessageForm.php, line 95

Class

PushNotificationsSendMessageForm
Class PushNotificationsSendMessageForm.

Namespace

Drupal\push_notifications\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $messageSender = \Drupal::service('push_notifications.message_sender_list');
  $messageSender
    ->setTokens($form_state
    ->getTemporaryValue('tokens'));
  $messageSender
    ->setMessage($form_state
    ->getValue('message'));
  $messageSender
    ->dispatch();
  $results = $messageSender
    ->getResults();

  // Display result for each network.
  foreach ($results as $network => $result) {
    if (empty($result['count_attempted'])) {

      // Only display results for networks with tokens.
      continue;
    }
    drupal_set_message($this
      ->t('@network: Attempted to send @count_attempted tokens, sent @count_success.', array(
      '@network' => strtoupper($network),
      '@count_attempted' => $result['count_attempted'],
      '@count_success' => $result['count_success'],
    )));
  }
}