You are here

vcardfield.install in VCard Field 7

File

vcardfield.install
View source
<?php

// $Id$

/**
 * Implementation of hook_field_schema().
 */
function vcardfield_field_schema($field) {
  if ($field['type'] == 'vcardfield') {
    $schema['columns']['prefix'] = array(
      'type' => 'varchar',
      'length' => '10',
      'not null' => FALSE,
    );
    $schema['columns']['first_name'] = array(
      'type' => 'varchar',
      'length' => '100',
      'not null' => FALSE,
    );
    $schema['columns']['middle_name'] = array(
      'type' => 'varchar',
      'length' => '100',
      'not null' => FALSE,
    );
    $schema['columns']['last_name'] = array(
      'type' => 'varchar',
      'length' => '100',
      'not null' => FALSE,
    );
    $schema['columns']['suffix'] = array(
      'type' => 'varchar',
      'length' => '25',
      'not null' => FALSE,
    );
    $schema['columns']['full_name'] = array(
      'type' => 'varchar',
      'length' => '255',
      'not null' => FALSE,
    );
    $schema['columns']['photo'] = array(
      'type' => 'varchar',
      'length' => '255',
      'not null' => FALSE,
    );
    $schema['columns']['title'] = array(
      'type' => 'varchar',
      'length' => '100',
      'not null' => FALSE,
    );
    $schema['columns']['organization'] = array(
      'type' => 'varchar',
      'length' => '100',
      'not null' => FALSE,
    );
    $schema['columns']['address_type'] = array(
      'type' => 'varchar',
      'length' => '4',
      'not null' => FALSE,
    );
    $schema['columns']['address'] = array(
      'type' => 'varchar',
      'length' => '255',
      'not null' => FALSE,
    );
    $schema['columns']['city'] = array(
      'type' => 'varchar',
      'length' => '100',
      'not null' => FALSE,
    );
    $schema['columns']['region'] = array(
      'type' => 'varchar',
      'length' => '100',
      'not null' => FALSE,
    );
    $schema['columns']['postalcode'] = array(
      'type' => 'varchar',
      'length' => '15',
      'not null' => FALSE,
    );
    $schema['columns']['country'] = array(
      'type' => 'varchar',
      'length' => '100',
      'not null' => FALSE,
    );
    $schema['columns']['phone_default'] = array(
      'type' => 'varchar',
      'length' => '25',
      'not null' => FALSE,
    );
    $schema['columns']['phone_cell'] = array(
      'type' => 'varchar',
      'length' => '25',
      'not null' => FALSE,
    );
    $schema['columns']['phone_fax'] = array(
      'type' => 'varchar',
      'length' => '25',
      'not null' => FALSE,
    );
    $schema['columns']['phone_home'] = array(
      'type' => 'varchar',
      'length' => '25',
      'not null' => FALSE,
    );
    $schema['columns']['email'] = array(
      'type' => 'varchar',
      'length' => '255',
      'not null' => FALSE,
    );
    $schema['columns']['link'] = array(
      'type' => 'varchar',
      'length' => '255',
      'not null' => FALSE,
    );
    $schema['columns']['label'] = array(
      'type' => 'varchar',
      'length' => '255',
      'not null' => FALSE,
    );
    $schema['columns']['instance'] = array(
      'type' => 'varchar',
      'length' => '255',
      'not null' => FALSE,
    );
    $schema['indexes'] = array(
      'name' => array(
        'last_name',
        'first_name',
      ),
      'link' => array(
        'link',
      ),
    );
    return $schema;
  }
}

/**
 * Implements hook_update_N().
 * Add photo field to table
 */
function vcardfield_update_7002(&$sandbox) {
  $fields = field_info_fields();
  foreach ($fields as $field_name => $field) {
    if ($field['type'] == 'vcardfield' && $field['storage']['type'] == 'field_sql_storage') {
      $schema = vcardfield_field_schema($field);
      foreach ($field['storage']['details']['sql'] as $type => $table_info) {
        foreach ($table_info as $table_name => $columns) {
          $column_name = _field_sql_storage_columnname($field_name, 'photo');
          if (!db_field_exists($table_name, $column_name)) {
            db_add_field($table_name, $column_name, $schema['columns']['photo']);
            db_add_index($table_name, $column_name, array(
              $column_name,
            ));
          }
        }
      }
    }
  }
  field_cache_clear();
}

/**
 * Implements hook_update_N().
 * Add middle name field
 */
function vcardfield_update_7003(&$sandbox) {
  $fields = field_info_fields();
  foreach ($fields as $field_name => $field) {
    if ($field['type'] == 'vcardfield' && $field['storage']['type'] == 'field_sql_storage') {
      $schema = vcardfield_field_schema($field);
      foreach ($field['storage']['details']['sql'] as $type => $table_info) {
        foreach ($table_info as $table_name => $columns) {
          $column_name = _field_sql_storage_columnname($field_name, 'middle_name');
          if (!db_field_exists($table_name, $column_name)) {
            db_add_field($table_name, $column_name, $schema['columns']['middle_name']);
            db_add_index($table_name, $column_name, array(
              $column_name,
            ));
          }
        }
      }
    }
  }
  field_cache_clear();
}

Functions

Namesort descending Description
vcardfield_field_schema Implementation of hook_field_schema().
vcardfield_update_7002 Implements hook_update_N(). Add photo field to table
vcardfield_update_7003 Implements hook_update_N(). Add middle name field