public function MessageForm::submitForm in Courier 2.x
Same name and namespace in other branches
- 8 courier_message_composer/src/Form/MessageForm.php \Drupal\courier_message_composer\Form\MessageForm::submitForm()
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
- courier_message_composer/
src/ Form/ MessageForm.php, line 222
Class
- MessageForm
- Create a message.
Namespace
Drupal\courier_message_composer\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
/** @var \Drupal\courier\ChannelInterface $message */
$message = $form_state
->get('message_entity');
$form_state
->get([
'form_display',
])
->extractFormValues($message, $form, $form_state);
$template_collection = TemplateCollection::create()
->setTemplate($message);
$identity = $form_state
->getValue('identity');
$mqi = $this->courierManager
->sendMessage($template_collection, $identity);
if ($mqi instanceof MessageQueueItemInterface) {
$this
->messenger()
->addMessage($this
->t('Message queued for delivery.'));
}
else {
$this
->messenger()
->addMessage($this
->t('Failed to send message'), 'error');
}
}