Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/sms_user/sms_user.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
arguments: ['@config.factory']
sms_user.account_registration:
class: Drupal\sms_user\AccountRegistration
arguments: ['@config.factory', '@token', '@sms.provider', '@sms.phone_number']
arguments: ['@config.factory', '@token', '@sms.provider', '@sms.phone_number.verification']
sms_user.sms_events:
class: Drupal\sms_user\EventSubscriber\SmsEventSubscriber
arguments: ['@sms_user.account_registration']
Expand Down
20 changes: 10 additions & 10 deletions modules/sms_user/src/AccountRegistration.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Utility\Token;
use Drupal\sms\Provider\SmsProviderInterface;
use Drupal\sms\Provider\PhoneNumberProviderInterface;
use Drupal\sms\Provider\PhoneNumberVerificationInterface;
use Drupal\sms\Message\SmsMessageInterface;
use Drupal\sms\Direction;
use Drupal\user\Entity\User;
Expand Down Expand Up @@ -42,11 +42,11 @@ class AccountRegistration implements AccountRegistrationInterface {
protected $smsProvider;

/**
* Phone number provider.
* Phone number verification provider.
*
* @var \Drupal\sms\Provider\PhoneNumberProviderInterface
* @var \Drupal\sms\Provider\PhoneNumberVerificationInterface
*/
protected $phoneNumberProvider;
protected $phoneNumberVerificationProvider;

/**
* Phone number settings for user.user bundle.
Expand All @@ -64,21 +64,21 @@ class AccountRegistration implements AccountRegistrationInterface {
* The token replacement system.
* @param \Drupal\sms\Provider\SmsProviderInterface $sms_provider
* The SMS provider.
* @param \Drupal\sms\Provider\PhoneNumberProviderInterface $phone_number_provider
* The phone number provider.
* @param \Drupal\sms\Provider\PhoneNumberVerificationInterface $phone_number_verification_provider
* The phone number verification provider.
*/
public function __construct(ConfigFactoryInterface $config_factory, Token $token, SmsProviderInterface $sms_provider, PhoneNumberProviderInterface $phone_number_provider) {
public function __construct(ConfigFactoryInterface $config_factory, Token $token, SmsProviderInterface $sms_provider, PhoneNumberVerificationInterface $phone_number_verification_provider) {
$this->configFactory = $config_factory;
$this->token = $token;
$this->smsProvider = $sms_provider;
$this->phoneNumberProvider = $phone_number_provider;
$this->phoneNumberVerificationProvider = $phone_number_verification_provider;
}

/**
* {@inheritdoc}
*/
public function createAccount(SmsMessageInterface $sms_message) {
$this->userPhoneNumberSettings = $this->phoneNumberProvider
$this->userPhoneNumberSettings = $this->phoneNumberVerificationProvider
->getPhoneNumberSettings('user', 'user');
if (!$this->userPhoneNumberSettings) {
// Can't do anything if there is no phone number settings for user.
Expand All @@ -88,7 +88,7 @@ public function createAccount(SmsMessageInterface $sms_message) {
$sender_number = $sms_message->getSenderNumber();
if (!empty($sender_number)) {
// Any users with this phone number?
$entities = $this->phoneNumberProvider
$entities = $this->phoneNumberVerificationProvider
->getPhoneVerificationByPhoneNumber($sender_number, NULL, 'user');
if (!count($entities)) {
if (!empty($this->settings('unrecognized_sender.status'))) {
Expand Down
20 changes: 10 additions & 10 deletions modules/sms_user/src/Form/AdminSettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,31 @@
use Drupal\Core\Render\Element;
use Drupal\Core\Url;
use Drupal\sms\Entity\PhoneNumberSettingsInterface;
use Drupal\sms\Provider\PhoneNumberProviderInterface;
use Drupal\sms\Provider\PhoneNumberVerificationInterface;

/**
* Provides a general settings form for SMS User.
*/
class AdminSettingsForm extends ConfigFormBase {

/**
* Phone number provider.
* Phone number verification provider.
*
* @var \Drupal\sms\Provider\PhoneNumberProviderInterface
* @var \Drupal\sms\Provider\PhoneNumberVerificationInterface
*/
protected $phoneNumberProvider;
protected $phoneNumberVerificationProvider;

/**
* Constructs a \Drupal\sms_user\Form\AdminSettingsForm object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The factory for configuration objects.
* @param \Drupal\sms\Provider\PhoneNumberProviderInterface $phone_number_provider
* The phone number provider.
* @param \Drupal\sms\Provider\PhoneNumberVerificationInterface $phone_number_verification_provider
* The phone number verification provider.
*/
public function __construct(ConfigFactoryInterface $config_factory, PhoneNumberProviderInterface $phone_number_provider) {
public function __construct(ConfigFactoryInterface $config_factory, PhoneNumberVerificationInterface $phone_number_verification_provider) {
parent::__construct($config_factory);
$this->phoneNumberProvider = $phone_number_provider;
$this->phoneNumberVerificationProvider = $phone_number_verification_provider;
}

/**
Expand All @@ -43,7 +43,7 @@ public function __construct(ConfigFactoryInterface $config_factory, PhoneNumberP
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory'),
$container->get('sms.phone_number')
$container->get('sms.phone_number.verification')
);
}

Expand Down Expand Up @@ -177,7 +177,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $op = NUL
$radio_value = 'none';
}

$user_phone_settings_exist = $this->phoneNumberProvider
$user_phone_settings_exist = $this->phoneNumberVerificationProvider
->getPhoneNumberSettings('user', 'user') instanceof PhoneNumberSettingsInterface;
if (!$user_phone_settings_exist) {
drupal_set_message($this->t('There are no phone number settings configured for the user entity type. Some features cannot operate without these settings. <a href=":add">Add phone number settings</a>.', [
Expand Down
20 changes: 10 additions & 10 deletions modules/sms_user/src/Plugin/Derivative/SmsUserMenuLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\sms\Provider\PhoneNumberProviderInterface;
use Drupal\sms\Provider\PhoneNumberVerificationInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
Expand All @@ -15,28 +15,28 @@
class SmsUserMenuLink extends DeriverBase implements ContainerDeriverInterface {

/**
* Phone number provider.
* The phone number verification service.
*
* @var \Drupal\sms\Provider\PhoneNumberProviderInterface
* @var \Drupal\sms\Provider\PhoneNumberVerificationInterface
*/
protected $phoneNumberProvider;
protected $phoneNumberVerification;

/**
* Constructs a \Drupal\sms_user\Plugin\Derivative\SmsUserMenuLink instance.
*
* @param \Drupal\sms\Provider\PhoneNumberProviderInterface $phone_number_provider
* The phone number provider.
* @param \Drupal\sms\Provider\PhoneNumberVerificationInterface $phone_number_verification
* The phone number verification service.
*/
public function __construct(PhoneNumberProviderInterface $phone_number_provider) {
$this->phoneNumberProvider = $phone_number_provider;
public function __construct(PhoneNumberVerificationInterface $phone_number_verification) {
$this->phoneNumberVerification = $phone_number_verification;
}

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static(
$container->get('sms.phone_number')
$container->get('sms.phone_number.verification')
);
}

Expand All @@ -46,7 +46,7 @@ public static function create(ContainerInterface $container, $base_plugin_id) {
public function getDerivativeDefinitions($base_plugin_definition) {
$links = [];

if ($this->phoneNumberProvider->getPhoneNumberSettings('user', 'user')) {
if ($this->phoneNumberVerification->getPhoneNumberSettings('user', 'user')) {
$links['sms_user_phone_number_settings'] = [
'title' => t('User phone number'),
'description' => t('Set up phone number fields and settings for users.'),
Expand Down
18 changes: 9 additions & 9 deletions sms.module
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ use Drupal\Core\Entity\ContentEntityInterface;
* Implements hook_cron().
*/
function sms_cron() {
/** @var \Drupal\sms\Provider\PhoneNumberProviderInterface $phone_number_provider */
$phone_number_provider = \Drupal::service('sms.phone_number');
$phone_number_provider->purgeExpiredVerifications();
/** @var \Drupal\sms\Provider\PhoneNumberVerificationInterface $phone_number_verification */
$phone_number_verification_provider = \Drupal::service('sms.phone_number.verification');
$phone_number_verification_provider->purgeExpiredVerifications();

/** @var \Drupal\sms\Provider\SmsQueueProcessorInterface $sms_queue_processor */
$sms_queue_processor = \Drupal::service('sms.queue');
Expand All @@ -42,9 +42,9 @@ function sms_entity_update(EntityInterface $entity) {
*/
function sms_entity_delete(EntityInterface $entity) {
if ($entity instanceof ContentEntityInterface) {
/** @var \Drupal\sms\Provider\PhoneNumberProviderInterface $phone_number_provider */
$phone_number_provider = \Drupal::service('sms.phone_number');
$phone_number_provider->deletePhoneVerificationByEntity($entity);
/** @var \Drupal\sms\Provider\PhoneNumberVerificationInterface $phone_number_verification_provider */
$phone_number_verification_provider = \Drupal::service('sms.phone_number.verification');
$phone_number_verification_provider->deletePhoneVerificationByEntity($entity);
}
}

Expand All @@ -57,8 +57,8 @@ function sms_entity_delete(EntityInterface $entity) {
*/
function _sms_entity_postsave(EntityInterface $entity) {
if ($entity instanceof ContentEntityInterface) {
/** @var \Drupal\sms\Provider\PhoneNumberProviderInterface $phone_number_provider */
$phone_number_provider = \Drupal::service('sms.phone_number');
$phone_number_provider->updatePhoneVerificationByEntity($entity);
/** @var \Drupal\sms\Provider\PhoneNumberVerificationInterface $phone_number_verification_provider */
$phone_number_verification_provider = \Drupal::service('sms.phone_number.verification');
$phone_number_verification_provider->updatePhoneVerificationByEntity($entity);
}
}
3 changes: 3 additions & 0 deletions sms.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ services:
arguments: ['@container.namespaces', '@cache.discovery', '@module_handler']
sms.phone_number:
class: Drupal\sms\Provider\PhoneNumberProvider
arguments: ['@sms.provider', '@sms.phone_number.verification']
sms.phone_number.verification:
class: Drupal\sms\Provider\PhoneNumberVerification
arguments: ['@entity_type.manager', '@config.factory', '@token', '@sms.provider']
sms.queue:
class: Drupal\sms\Provider\SmsQueueProcessor
Expand Down
24 changes: 12 additions & 12 deletions src/Form/VerifyPhoneNumberForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Drupal\Core\Form\FormBase;
use Drupal\Core\Flood\FloodInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\sms\Provider\PhoneNumberProviderInterface;
use Drupal\sms\Provider\PhoneNumberVerificationInterface;
use Drupal\Core\Form\FormStateInterface;

/**
Expand All @@ -21,23 +21,23 @@ class VerifyPhoneNumberForm extends FormBase {
protected $flood;

/**
* Phone number provider.
* The phone number verification service.
*
* @var \Drupal\sms\Provider\PhoneNumberProviderInterface
* @var \Drupal\sms\Provider\PhoneNumberVerificationInterface
*/
protected $phoneNumberProvider;
protected $phoneNumberVerification;

/**
* Constructs a VerifyPhoneNumberForm object.
*
* @param \Drupal\Core\Flood\FloodInterface $flood
* The flood control mechanism.
* @param \Drupal\sms\Provider\PhoneNumberProviderInterface $phone_number_provider
* The phone number provider.
* @param \Drupal\sms\Provider\PhoneNumberVerificationInterface $phone_number_verification
* The phone number verification service.
*/
public function __construct(FloodInterface $flood, PhoneNumberProviderInterface $phone_number_provider) {
public function __construct(FloodInterface $flood, PhoneNumberVerificationInterface $phone_number_verification) {
$this->flood = $flood;
$this->phoneNumberProvider = $phone_number_provider;
$this->phoneNumberVerification = $phone_number_verification;
}

/**
Expand All @@ -46,7 +46,7 @@ public function __construct(FloodInterface $flood, PhoneNumberProviderInterface
public static function create(ContainerInterface $container) {
return new static(
$container->get('flood'),
$container->get('sms.phone_number')
$container->get('sms.phone_number.verification')
);
}

Expand Down Expand Up @@ -92,12 +92,12 @@ public function validateForm(array &$form, FormStateInterface $form_state) {

$current_time = $this->getRequest()->server->get('REQUEST_TIME');
$code = $form_state->getValue('code');
$phone_verification = $this->phoneNumberProvider
$phone_verification = $this->phoneNumberVerification
->getPhoneVerificationByCode($code);

if ($phone_verification && !$phone_verification->getStatus()) {
$entity = $phone_verification->getEntity();
$phone_number_settings = $this->phoneNumberProvider
$phone_number_settings = $this->phoneNumberVerification
->getPhoneNumberSettingsForEntity($entity);
$lifetime = $phone_number_settings->getVerificationCodeLifetime() ?: 0;

Expand All @@ -118,7 +118,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$code = $form_state->getValue('code');
$phone_verification = $this->phoneNumberProvider
$phone_verification = $this->phoneNumberVerification
->getPhoneVerificationByCode($code);
$phone_verification
->setStatus(TRUE)
Expand Down
20 changes: 10 additions & 10 deletions src/Lists/PhoneNumberSettingsListBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Drupal\sms\Provider\PhoneNumberProviderInterface;
use Drupal\sms\Provider\PhoneNumberVerificationInterface;
use Drupal\Core\Entity\EntityInterface;

/**
Expand All @@ -23,11 +23,11 @@ class PhoneNumberSettingsListBuilder extends ConfigEntityListBuilder {
protected $phoneNumberVerificationStorage;

/**
* Phone number provider.
* Phone number verification provider.
*
* @var \Drupal\sms\Provider\PhoneNumberProviderInterface
* @var \Drupal\sms\Provider\PhoneNumberVerificationInterface
*/
protected $phoneNumberProvider;
protected $phoneNumberVerificationProvider;

/**
* Current request time.
Expand All @@ -45,7 +45,7 @@ public static function createInstance(ContainerInterface $container, EntityTypeI
$container->get('entity.manager')->getStorage($entity_type->id()),
$container->get('entity_type.manager')->getStorage('sms_phone_number_verification'),
$container->get('request_stack'),
$container->get('sms.phone_number')
$container->get('sms.phone_number.verification')
);
}

Expand All @@ -56,13 +56,13 @@ public static function createInstance(ContainerInterface $container, EntityTypeI
* Storage for Phone Number Verification entities.
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack.
* @param \Drupal\sms\Provider\PhoneNumberProviderInterface $phone_number_provider
* The phone number provider.
* @param \Drupal\sms\Provider\PhoneNumberVerificationInterface $phone_number_verification_provider
* The phone number verification provider.
*/
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, EntityStorageInterface $phone_number_verification_storage, RequestStack $request_stack, PhoneNumberProviderInterface $phone_number_provider) {
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, EntityStorageInterface $phone_number_verification_storage, RequestStack $request_stack, PhoneNumberVerificationInterface $phone_number_verification_provider) {
parent::__construct($entity_type, $storage);
$this->phoneNumberVerificationStorage = $phone_number_verification_storage;
$this->phoneNumberProvider = $phone_number_provider;
$this->phoneNumberVerificationProvider = $phone_number_verification_provider;
$this->requestTime = $request_stack
->getCurrentRequest()
->server
Expand Down Expand Up @@ -92,7 +92,7 @@ public function buildRow(EntityInterface $entity) {
$row['entity_type'] = $entity_type_id;
$row['bundle'] = $bundle;

$phone_number_settings = $this->phoneNumberProvider
$phone_number_settings = $this->phoneNumberVerificationProvider
->getPhoneNumberSettings($entity_type_id, $bundle);
$lifetime = $phone_number_settings->getVerificationCodeLifetime() ?: 0;

Expand Down
8 changes: 4 additions & 4 deletions src/Plugin/Field/FieldWidget/SmsTelephoneWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ class SmsTelephoneWidget extends TelephoneDefaultWidget {
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$element = parent::formElement($items, $delta, $element, $form, $form_state);

/** @var \Drupal\sms\Provider\PhoneNumberProviderInterface $phone_number_provider */
$phone_number_provider = \Drupal::service('sms.phone_number');
/** @var \Drupal\sms\Provider\PhoneNumberVerificationInterface $phone_number_verification_provider */
$phone_number_verification_provider = \Drupal::service('sms.phone_number.verification');
try {
$config = $phone_number_provider->getPhoneNumberSettingsForEntity($items->getEntity());
$config = $phone_number_verification_provider->getPhoneNumberSettingsForEntity($items->getEntity());
}
catch (PhoneNumberSettingsException $e) {
return $element;
Expand All @@ -46,7 +46,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
$lifetime = $config->getVerificationCodeLifetime() ?: 0;

if (isset($items[$delta]->value)) {
$phone_verification = $phone_number_provider
$phone_verification = $phone_number_verification_provider
->getPhoneVerificationByEntity($items->getEntity(), $items[$delta]->value);

if ($phone_verification) {
Expand Down
Loading