2013-01-18 18:17:06 +00:00
|
|
|
<?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',
|
2013-06-25 10:27:47 +00:00
|
|
|
'class' => 'Drupal\telephone\Type\TelephoneItem',
|
2013-01-18 18:17:06 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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().
|
|
|
|
*/
|
2013-06-16 08:27:11 +00:00
|
|
|
function telephone_field_is_empty($item, $field_type) {
|
2013-01-18 18:17:06 +00:00
|
|
|
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';
|
|
|
|
}
|
|
|
|
}
|