You are here

mobile_number.install in Mobile Number 8

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

Install, update and uninstall functions for the systementity_configfield module.

File

mobile_number.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the systementity_configfield module.
 */

/**
 * Implements hook_schema().
 */
function mobile_number_schema() {
  $schema['mobile_number_verification'] = [
    'description' => 'A table for storing verification codes for mobile numbers.',
    'fields' => [
      'token' => [
        'description' => 'Verification token.',
        'type' => 'varchar',
        'length' => 43,
        'not null' => TRUE,
      ],
      'timestamp' => [
        'description' => 'The time when the verification token was created.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ],
      'verification_code' => [
        'description' => 'Hash of the code sent to the user.',
        'type' => 'varchar',
        'length' => 40,
        'not null' => TRUE,
      ],
    ],
    'indexes' => [
      'token_created' => [
        'timestamp',
      ],
    ],
    'primary key' => [
      'token',
    ],
  ];
  return $schema;
}

/**
 * Implements hook_install().
 */
function mobile_number_install() {
  \Drupal::configFactory()
    ->getEditable('mobile_number.settings')
    ->set('verification_secret', \Drupal::csrfToken()
    ->get('mobile number secret' . rand(0, 999999999)))
    ->save();
}

/**
 * Implements hook_requirements().
 */
function mobile_number_requirements($phase) {
  $requirements = [];
  $requirements['mobile_number_library'] = [
    'title' => t('Libphonenumber-for-php library'),
  ];
  if (class_exists('\\libphonenumber\\PhoneNumber')) {
    $requirements['mobile_number_library']['value'] = t('Installed');
    $requirements['mobile_number_library']['severity'] = REQUIREMENT_OK;
  }
  else {
    $requirements['mobile_number_library']['value'] = t('Not Installed');
    $requirements['mobile_number_library']['severity'] = REQUIREMENT_ERROR;
    $requirements['mobile_number_library']['description'] = t('Please install the libphonenumber-for-php library via Composer.');
  }
  return $requirements;
}