email.module 1.46 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
<?php

/**
 * @file
 * Defines a simple e-mail field type.
 */

/**
 * Implements hook_help().
 */
function email_help($path, $arg) {
  switch ($path) {
    case 'admin/help#email':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('The E-mail module defines a field for storing e-mail addresses, for use with the Field module. E-mail addresses are validated to ensure they match the expected format. See the <a href="@field-help">Field module help page</a> for more information about fields.', array('@field-help' => url('admin/help/field'))) . '</p>';
      return $output;
  }
}

/**
 * Implements hook_field_info().
 */
function email_field_info() {
  return array(
    'email' => array(
      'label' => t('E-mail'),
      'description' => t('This field stores an e-mail address in the database.'),
      'default_widget' => 'email_default',
30
      'default_formatter' => 'email_mailto',
31 32 33 34 35
    ),
  );
}

/**
36
 * Implements hook_field_info_alter().
37
 */
38 39 40 41
function email_field_info_alter(&$info) {
  if (module_exists('text')) {
    $info['email']['default_formatter'] = 'text_plain';
  }
42 43 44
}

/**
45
 * Implements hook_field_is_empty().
46
 */
47 48
function email_field_is_empty($item, $field) {
  return !isset($item['value']) || $item['value'] === '';
49 50 51 52 53 54
}

/**
 * Implements hook_field_formatter_info_alter().
 */
function email_field_formatter_info_alter(&$info) {
55 56
  if (isset($info['text_plain'])) {
    $info['text_plain']['field_types'][] = 'email';
57 58
  }
}