smsplatform-1.0.x-dev/smsplatform.module

smsplatform.module
<?php

/**
 * @file
 * Provides hooks for SMS Platform.
 */

declare(strict_types=1);

use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityInterface;

/**
 * Implements hook_cron().
 */
function smsplatform_cron(): void {
  /** @var \Drupal\smsplatform\Provider\PhoneNumberVerificationInterface $phone_number_verification */
  $phone_number_verification_provider = \Drupal::service('smsplatform.phonenumber.verification');
  $phone_number_verification_provider->purgeExpiredVerifications();

  /** @var \Drupal\smsplatform\Provider\SmsQueueProcessorInterface $sms_queue_processor */
  $sms_queue_processor = \Drupal::service('smsplatform.queue');
  $sms_queue_processor->processUnqueued();
  $sms_queue_processor->garbageCollection();
}

/**
 * Implements hook_entity_insert().
 */
function smsplatform_entity_insert(EntityInterface $entity): void {
  _smsplatform_entity_postsave($entity);
}

/**
 * Implements hook_entity_update().
 */
function smsplatform_entity_update(EntityInterface $entity): void {
  _smsplatform_entity_postsave($entity);
}

/**
 * Implements hook_entity_delete().
 */
function smsplatform_entity_delete(EntityInterface $entity): void {
  if ($entity instanceof ContentEntityInterface) {
    /** @var \Drupal\smsplatform\Provider\PhoneNumberVerificationInterface $phone_number_verification_provider */
    $phone_number_verification_provider = \Drupal::service('smsplatform.phonenumber.verification');
    $phone_number_verification_provider->deletePhoneVerificationByEntity($entity);
  }
}

/**
 * Respond to saving entities after they have been written to storage.
 *
 * @link https://www.drupal.org/node/2221347
 * @see sms_entity_insert()
 * @see sms_entity_update()
 */
function _smsplatform_entity_postsave(EntityInterface $entity): void {
  if ($entity instanceof ContentEntityInterface) {
    /** @var \Drupal\smsplatform\Provider\PhoneNumberVerificationInterface $phone_number_verification_provider */
    $phone_number_verification_provider = \Drupal::service('smsplatform.phonenumber.verification');
    $phone_number_verification_provider->updatePhoneVerificationByEntity($entity);
  }
}

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

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