You are here

static function MoAuthUtilities::getUserPhoneNumber in Google Authenticator / 2 Factor Authentication - 2FA 8.2

3 calls to MoAuthUtilities::getUserPhoneNumber()
configure_otp_over_sms_and_email::buildForm in src/Form/configure_otp_over_sms_and_email.php
Form constructor.
miniorange_2fa_inline_registration::mo_auth_get_otp_over_sms_authentication_form in src/Form/miniorange_2fa_inline_registration.php
MoAuthSupport::buildForm in src/Form/MoAuthSupport.php
Form constructor.

File

src/MoAuthUtilities.php, line 792
This file is part of miniOrange 2FA module.

Class

MoAuthUtilities

Namespace

Drupal\miniorange_2fa

Code

static function getUserPhoneNumber($uid) {
  $variables_and_values = array(
    'auto_fetch_phone_number',
    'phone_number_field_machine_name',
    'auto_fetch_phone_number_country_code',
  );
  $mo_db_values = self::miniOrange_set_get_configurations($variables_and_values, "GET");
  if ($mo_db_values['auto_fetch_phone_number']) {
    $fieldName = $mo_db_values['phone_number_field_machine_name'];
    $user = User::load($uid);
    $countryCode = $phone = $mo_db_values['auto_fetch_phone_number_country_code'];
    if (!is_null($user)) {
      $user = $user
        ->toArray();
      if (isset($user[$fieldName]['0']['value'])) {
        $phone = $user[$fieldName]['0']['value'];
      }
      if (strpos($phone, "+") === FALSE) {
        $phone = strval($countryCode) . strval($phone);
      }
    }
    return $phone;
  }
  return null;
}