You are here

mobile_number.module in Mobile Number 8

Same filename and directory in other branches
  1. 7 mobile_number.module
  2. 2.0.x mobile_number.module

File

mobile_number.module
View source
<?php

/**
 * @file
 * mobile_number.module
 */
use Drupal\sms\Exception\RecipientRouteException;
use Drupal\sms\Message\SmsMessage;

/**
 * Implements hook_menu().
 */
function mobile_number_menu() {
  $items = [];
  return $items;
}

/**
 * Implements hook_form_alter().
 */
function mobile_number_form_alter($form, $form_state, $form_id) {

  // print_r($form_id);
}

/**
 * Sms framework integration, send sms callback.
 *
 * @param string $number
 *   E.164 Number.
 * @param string $message
 *   The Message.
 *
 * @return bool
 *   Send status.
 */
function mobile_number_send_sms($number, $message) {

  /** @var \Drupal\sms\Provider\DefaultSmsProvider $sms_provider */
  $sms_provider = \Drupal::service('sms.provider');
  try {
    $sms_message = new SmsMessage(NULL, [
      $number,
    ], $message);

    /** @var \Drupal\sms\Message\SmsMessageResultInterface $result */
    $result = $sms_provider
      ->send($sms_message)[0];
    return $result
      ->getResult()
      ->getReport($number)
      ->getStatus();
  } catch (RecipientRouteException $e) {
    return FALSE;
  }
}

/**
 * Helper function for get all supported countries for views.
 */
function mobile_number_views_country_options($allowed_countries = []) {

  /** @var \Drupal\mobile_number\MobileNumberUtilInterface $util */
  $util = \Drupal::service('mobile_number.util');
  return $util
    ->getCountryOptions($allowed_countries, TRUE);
}

Functions

Namesort descending Description
mobile_number_form_alter Implements hook_form_alter().
mobile_number_menu Implements hook_menu().
mobile_number_send_sms Sms framework integration, send sms callback.
mobile_number_views_country_options Helper function for get all supported countries for views.