You are here

sms.module in SMS Framework 8

Provides hooks for SMS Framework.

File

sms.module
View source
<?php

/**
 * @file
 * Provides hooks for SMS Framework.
 */
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\ContentEntityInterface;

/**
 * Implements hook_cron().
 */
function sms_cron() {

  /** @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');
  $sms_queue_processor
    ->processUnqueued();
  $sms_queue_processor
    ->garbageCollection();
}

/**
 * Implements hook_entity_insert().
 */
function sms_entity_insert(EntityInterface $entity) {
  _sms_entity_postsave($entity);
}

/**
 * Implements hook_entity_update().
 */
function sms_entity_update(EntityInterface $entity) {
  _sms_entity_postsave($entity);
}

/**
 * Implements hook_entity_delete().
 */
function sms_entity_delete(EntityInterface $entity) {
  if ($entity instanceof ContentEntityInterface) {

    /** @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);
  }
}

/**
 * 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 _sms_entity_postsave(EntityInterface $entity) {
  if ($entity instanceof ContentEntityInterface) {

    /** @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);
  }
}

Functions

Namesort descending Description
sms_cron Implements hook_cron().
sms_entity_delete Implements hook_entity_delete().
sms_entity_insert Implements hook_entity_insert().
sms_entity_update Implements hook_entity_update().
_sms_entity_postsave Respond to saving entities after they have been written to storage.