You are here

function phone_field_formatter in Phone 6

Same name and namespace in other branches
  1. 5 phone.module \phone_field_formatter()

Implementation of hook_field_formatter().

Prepare an individual item for viewing in a browser.


$field: The field the action is being performed on.

$item: An array, keyed by column, of the data stored for this item in this field.

$formatter: The name of the formatter being used to display the field.

$node: The node object, for context. Will be NULL in some cases. Warning: when displaying field retrieved by Views, $node will not be a "full-fledged" node object, but an object containg the data returned by the Views query (at least nid, vid, changed)

Return value

An HTML string containing the formatted item.

In a multiple-value field scenario, this function will be called once per value currently stored in the field. This function is also used as the handler for viewing a field in a views.module tabular listing.

It is important that this function at the minimum perform security transformations such as running check_plain() or check_markup().


./phone.module, line 603
Defines phone number fields for CCK. Provide some verifications on the phone numbers


function phone_field_formatter($field, $item, $formatter, $node) {
  if (!isset($item['value'])) {
    return '';
  if ($field['text_processing']) {
    $text = check_markup($item['value'], $item['format'], is_null($node) || isset($node->in_preview));
  else {
    $text = check_plain($item['value']);

  // iPhone Support
  if (strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') !== FALSE) {
    $text = '<a href="tel:' . $text . '">' . $text . '</a>';
  return $text;