You are here

function telephone_field_formatter_view in Telephone 7

Implements hook_field_formatter_view().

File

./telephone.module, line 167
Defines a simple telephone number field type.

Code

function telephone_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  $settings = $display['settings'];
  foreach ($items as $delta => $item) {

    // Prepend 'tel:' to the telephone number.
    $href = 'tel:' . rawurlencode(preg_replace('/\\s+/', '', $item['value']));

    // Render each element as link.
    $element[$delta] = array(
      '#type' => 'link',
      '#title' => $item['title'],
      '#href' => $href,
      '#options' => array(
        'external' => TRUE,
      ),
    );
  }
  return $element;
}