telephone.module 1.02 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php

/**
 * @file
 * Defines a simple telephone number field type.
 */

/**
 * Implements hook_field_info().
 */
function telephone_field_info() {
  return array(
    'telephone' => array(
      'label' => t('Telephone number'),
      'description' => t('This field stores a telephone number in the database.'),
      'default_widget' => 'telephone_default',
      'default_formatter' => 'telephone_link',
18
      'field item class' => 'Drupal\telephone\Type\TelephoneItem',
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
    ),
  );
}

/**
 * Implements hook_field_info_alter().
 */
function telephone_field_info_alter(&$info) {
  if (module_exists('text')) {
    $info['telephone']['default_formatter'] = 'text_plain';
  }
}

/**
 * Implements hook_field_is_empty().
 */
function telephone_field_is_empty($item, $field) {
  return !isset($item['value']) || $item['value'] === '';
}

/**
 * Implements hook_field_formatter_info_alter().
 */
function telephone_field_formatter_info_alter(&$info) {
  if (isset($info['text_plain'])) {
    $info['text_plain']['field_types'][] = 'telephone';
  }
}