smsplatform-1.0.x-dev/modules/smsplatform_user/src/EventSubscriber/SmsEventSubscriber.php

modules/smsplatform_user/src/EventSubscriber/SmsEventSubscriber.php
<?php

declare(strict_types=1);

namespace Drupal\smsplatform_user\EventSubscriber;

use Drupal\smsplatform\Event\SmsEvents;
use Drupal\smsplatform\Event\SmsMessageEvent;
use Drupal\smsplatform_user\AccountRegistrationInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
 * Event subscriber responding to SMS Platform events.
 */
class SmsEventSubscriber implements EventSubscriberInterface {

  /**
   * Constructs a new SmsEvents instance.
   *
   * @param \Drupal\smsplatform_user\AccountRegistrationInterface $accountRegistration
   *   The account registration service.
   */
  public function __construct(
    protected AccountRegistrationInterface $accountRegistration,
  ) {
  }

  /**
   * Process an incoming SMS to see if a new account should be created.
   *
   * @param \Drupal\smsplatform\Event\SmsMessageEvent $event
   *   The event.
   */
  public function createAccount(SmsMessageEvent $event) {
    foreach ($event->getMessages() as $sms_message) {
      $this->accountRegistration->createAccount($sms_message);
    }
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events[SmsEvents::MESSAGE_INCOMING_POST_PROCESS][] = ['createAccount'];
    return $events;
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc