You are here

postal_code.install in Postal Code 7

Based on example from http://www.slideshare.net/zugec/fields-in-core-how-to-create-a-custom-field and http://drupal.org/project/examples.

I envision that every update which contains new countries in the postal_code_regexes.inc file will begin with saving the "postal_code_valid_countries" Drupal variable to a PHP variable and then running the functionality within postal_code_uninstall() and then postal_code_install(). According to research,the longest postal_codes in the world are 10 chars. Padding, just to make sure.

File

postal_code.install
View source
<?php

/**
 * @file
 * Based on example from
 *  http://www.slideshare.net/zugec/fields-in-core-how-to-create-a-custom-field
 * and
 * http://drupal.org/project/examples.
 *
 * I envision that every update which contains new countries in the
 * postal_code_regexes.inc file will begin with saving
 * the "postal_code_valid_countries" Drupal variable to a PHP variable
 * and then running the functionality within
 * postal_code_uninstall() and then postal_code_install().
 * According to research,the longest postal_codes in the world are 10 chars.
 * Padding, just to make sure.
 */

/**
 * Implements hook_uninstall().
 */
function postal_code_uninstall() {

  // Delete all variables set in variable table.
  variable_del('postal_code_validate');
  variable_del('postal_code_valid_countries');
  drupal_set_message(st('Postal Code module has been uninstalled successfully.'));
}

/**
 * Implements hook_field_schema().
 */
function postal_code_field_schema($field) {
  if ($field['type'] == 'postal_code') {
    $columns = array(
      'postal' => array(
        'type' => 'varchar',
        'length' => '16',
        'not null' => FALSE,
      ),
    );
  }
  return array(
    'columns' => $columns,
  );
}

Functions