function mobile_number_value_callback in Mobile Number 7
Mobile number element value callback.
1 string reference to 'mobile_number_value_callback'
- mobile_number_element_info in ./
mobile_number.module - Implements hook_element_info().
File
- ./
mobile_number.module, line 694 - mobile_number.module
Code
function mobile_number_value_callback($element, $input = FALSE) {
$result = array();
if ($input) {
try {
$settings = $element['#mobile_number'];
$settings += array(
'allowed_countries' => array(),
);
$country = !empty($input['country-code']) ? $input['country-code'] : (count($settings['allowed_countries']) == 1 ? key($settings['allowed_countries']) : NULL);
$mobile_number = new MobileNumber($input['mobile'], $country);
if (!empty($input['verification_token']) && !empty($input['verification_code'])) {
$mobile_number
->verifyCode($input['verification_code'], $input['verification_token']);
}
$result = array(
'value' => $mobile_number->callableNumber,
'country' => $mobile_number->country,
'local_number' => $mobile_number->localNumber,
'verified' => $mobile_number
->isVerified() || !empty($element['#default_value']['verified']) && $mobile_number->callableNumber == $element['#default_value']['value'] ? 1 : 0,
'tfa' => !empty($input['tfa']) ? 1 : 0,
);
} catch (Exception $e) {
if (strlen($input['mobile'])) {
// A value was submitted, so the resultant array should not be empty.
$result['value'] = '';
}
}
}
else {
$result = !empty($element['#default_value']['value']) ? $element['#default_value'] : array();
}
return $result;
}