public function SmsDevelMessageForm::validateForm in SMS Framework 8
Form validation 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 FormBase::validateForm
File
- modules/
sms_devel/ src/ Form/ SmsDevelMessageForm.php, line 154
Class
- SmsDevelMessageForm
- Simulate a message being sent or received.
Namespace
Drupal\sms_devel\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
$number = $form_state
->getValue('number');
$message = $form_state
->getValue('message');
$automated = !empty($form_state
->getValue('automated'));
$this->message = SmsMessage::create()
->addRecipient($number)
->setMessage($message)
->setAutomated($automated);
$send_on = $form_state
->getValue('send_on');
if ($send_on instanceof DrupalDateTime) {
$this->message
->setSendTime($send_on
->format('U'));
}
$triggering_element = $form_state
->getTriggeringElement();
$gateway = $form_state
->getValue('gateway');
if (!empty($gateway)) {
$this->message
->setGateway(SmsGateway::load($gateway));
}
elseif ($triggering_element['#name'] == 'receive') {
$form_state
->setError($form['gateway'], $this
->t('Gateway must be selected if receiving a message.'));
}
}