protected function MobileNumber::prepareValue in Mobile Number 8
Same name and namespace in other branches
- 2.0.x src/Feeds/Target/MobileNumber.php \Drupal\mobile_number\Feeds\Target\MobileNumber::prepareValue()
Prepares a single value.
Parameters
int $delta: The field delta.
array $values: The values.
Overrides FieldTargetBase::prepareValue
File
- src/
Feeds/ Target/ MobileNumber.php, line 36
Class
- MobileNumber
- Defines a mobile number field mapper.
Namespace
Drupal\mobile_number\Feeds\TargetCode
protected function prepareValue($delta, array &$values) {
/** @var MobileNumberUtilInterface $util */
$util = \Drupal::service('mobile_number.util');
$mobile_number = FALSE;
if (!empty($values['local_number']) && !empty($values['country'])) {
$mobile_number = $util
->getMobileNumber($values['local_number'], $values['country']);
}
else {
$mobile_number = $util
->getMobileNumber($values['value']);
}
if ($mobile_number) {
$values['value'] = $util
->getCallableNumber($mobile_number);
$values['local_number'] = $util
->getLocalNumber($mobile_number);
$values['country'] = $util
->getCountry($mobile_number);
$values['tfa'] = !empty($values['tfa']) ? 1 : 0;
if (!empty($values['verified'])) {
$code = $util
->generateVerificationCode();
$token = $util
->registerVerificationCode($mobile_number, $code);
$values['verification_code'] = $code;
$values['verification_token'] = $token;
}
$values['verified'] = 0;
}
else {
$values = [];
}
}