Skip to content

Verifications can be conditionally sent for entities/objects. For example, you may want to disable verifications for trusted/elevated users. Or inversely, disable verifications for regular users.

Event subscriber

yaml
services:
  _defaults:
    autoconfigure: true
    autowire: true
    
  Drupal\my_module\EventListener\MyEntityPhoneNumberVerification: ~
php
namespace Drupal\my_module\EventListener;

use Drupal\sms\PhoneNumberVerification\Event\EntityPhoneNumberVerification;
use Drupal\notifier\Recipients\Recipient\EmailRecipient;
use Drupal\user\UserInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

final class MyEntityPhoneNumberVerification implements EventSubscriberInterface {
  public function onPhoneNumberVerification(EntityPhoneNumberVerification $event): void {
    // Context is provided in $event->getObject() and $event->getPhoneNumber().
    $entityOrObject = $event->getObject();
    $phoneNumber = $event->getPhoneNumber();
    // Modify whether verifications are enabled with 
    $event->shallSendVerification(bool);
  }

  public static function getSubscribedEvents(): array {
    return [EntityPhoneNumberVerification::class => 'onPhoneNumberVerification'];
  }
}