class SmsEntityPhoneNumberProcessor in SMS Framework 8
Same name and namespace in other branches
- 2.x src/EventSubscriber/SmsEntityPhoneNumberProcessor.php \Drupal\sms\EventSubscriber\SmsEntityPhoneNumberProcessor
- 2.1.x src/EventSubscriber/SmsEntityPhoneNumberProcessor.php \Drupal\sms\EventSubscriber\SmsEntityPhoneNumberProcessor
Resolve phone numbers for an entity using phone verification system.
Hierarchy
- class \Drupal\sms\EventSubscriber\SmsEntityPhoneNumberProcessor implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of SmsEntityPhoneNumberProcessor
1 string reference to 'SmsEntityPhoneNumberProcessor'
1 service uses SmsEntityPhoneNumberProcessor
File
- src/
EventSubscriber/ SmsEntityPhoneNumberProcessor.php, line 14
Namespace
Drupal\sms\EventSubscriberView source
class SmsEntityPhoneNumberProcessor implements EventSubscriberInterface {
/**
* The phone number verification service.
*
* @var \Drupal\sms\Provider\PhoneNumberVerificationInterface
*/
protected $phoneNumberVerification;
/**
* Constructs a new SmsEntityPhoneNumberProcessor object.
*
* @param \Drupal\sms\Provider\PhoneNumberVerificationInterface $phone_number_verification
* The phone number verification service.
*/
public function __construct(PhoneNumberVerificationInterface $phone_number_verification) {
$this->phoneNumberVerification = $phone_number_verification;
}
/**
* Get phone numbers for an entity using phone verification system.
*
* @param \Drupal\sms\Event\SmsEntityPhoneNumber $event
* The entity phone number event.
*/
public function entityPhoneNumbers(SmsEntityPhoneNumber $event) {
$entity = $event
->getEntity();
try {
$phone_number_settings = $this->phoneNumberVerification
->getPhoneNumberSettingsForEntity($entity);
$field_name = $phone_number_settings
->getFieldName('phone_number');
if (!$field_name) {
return;
}
} catch (PhoneNumberSettingsException $e) {
return;
}
$phone_numbers = [];
if (isset($entity->{$field_name})) {
foreach ($entity->{$field_name} as $item) {
$phone_numbers[] = $item->value;
}
}
$verified = $event
->getRequiresVerification();
foreach ($phone_numbers as $phone_number) {
if (!isset($verified)) {
$event
->addPhoneNumber($phone_number);
}
else {
$verification = $this->phoneNumberVerification
->getPhoneVerificationByEntity($entity, $phone_number);
if ($verification && $verification
->getStatus() == $verified) {
$event
->addPhoneNumber($phone_number);
}
}
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[SmsEvents::ENTITY_PHONE_NUMBERS][] = [
'entityPhoneNumbers',
1024,
];
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SmsEntityPhoneNumberProcessor:: |
protected | property | The phone number verification service. | |
SmsEntityPhoneNumberProcessor:: |
public | function | Get phone numbers for an entity using phone verification system. | |
SmsEntityPhoneNumberProcessor:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
SmsEntityPhoneNumberProcessor:: |
public | function | Constructs a new SmsEntityPhoneNumberProcessor object. |