Skip to content
Snippets Groups Projects
Commit 30f78e89 authored by Malcolm Young's avatar Malcolm Young
Browse files

Issue #3379748: Sending SMS to new users should be configurable

parent 3b8554d6
No related branches found
No related tags found
1 merge request!31Issue #3379748: Sending SMS to new users should be configurable
......@@ -148,6 +148,12 @@ class TwilioAdminForm extends ConfigFormBase {
],
'#default_value' => $config->get('registration_form'),
];
$form['registration_send'] = [
'#type' => 'checkbox',
'#title' => $this->t('Send confirmation SMS on registration'),
'#default_value' => $config->get('registration_send'),
];
$form['twilio_country_codes_container'] = [
'#tree' => TRUE,
......
......@@ -51,7 +51,13 @@ function twilio_form_user_register_form_alter(&$form, FormStateInterface $form_s
'#required' => $required,
];
$form['#validate'][] = 'twilio_register_validate';
$form['actions']['submit']['#submit'][] = 'twilio_register_submit';
// Is the site configured to send SMS on registration?
$send_sms = \Drupal::config('twilio.settings')->get('registration_send');
if (!empty($send_sms)) {
$form['actions']['submit']['#submit'][] = 'twilio_register_submit';
}
}
......@@ -77,16 +83,15 @@ function twilio_register_validate($form, FormStateInterface $form_state) {
* Custom submit handler for phone numbers during registration.
*/
function twilio_register_submit($form, FormStateInterface $form_state) {
$value = $form_state->getValues();
$values = $form_state->getValues();
// Phone number is not required and not entered.
if (empty($value['number']) && empty($form['account']['number']['#required'])) {
// No phone number entered, don't try to send SMS.
if (empty($values['number'])) {
return;
}
else {
$account = User::load($value['uid']);
\Drupal::service('twilio.sms')->twilioUserSendConfirmation($account, $value['number'], $value['countrycode']);
}
$account = User::load($values['uid']);
\Drupal::service('twilio.sms')->twilioUserSendConfirmation($account, $values['number'], $values['countrycode']);
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment