You are here

public function NodeTabForm::submitSendNow in Simplenews 8

Submit handler for sending published newsletter issue.

Parameters

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

File

src/Form/NodeTabForm.php, line 302

Class

NodeTabForm
Configure simplenews subscriptions of a user.

Namespace

Drupal\simplenews\Form

Code

public function submitSendNow(array &$form, FormStateInterface $form_state) {
  $node = $form_state
    ->get('node');
  $this->spoolStorage
    ->addFromEntity($node);

  // Attempt to send immediatly, if configured to do so.
  if ($this->mailer
    ->attemptImmediateSend(array(
    'entity_id' => $node
      ->id(),
    'entity_type' => 'node',
  ))) {
    $this
      ->messenger()
      ->addMessage(t('Newsletter %title sent.', array(
      '%title' => $node
        ->getTitle(),
    )));
  }
  else {
    $this
      ->messenger()
      ->addMessage(t('Newsletter issue %title pending.', array(
      '%title' => $node
        ->getTitle(),
    )));
  }
  $node
    ->save();
}