You are here

function international_phone_field_formatter_view in International Phone Field 7

Same name and namespace in other branches
  1. 7.2 international_phone.module \international_phone_field_formatter_view()

Implements hook_field_formatter_view().

File

./international_phone.module, line 49
Allow users to add international phone fields with a entity.

Code

function international_phone_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  foreach ($items as $delta => $item) {
    $text = '';
    if (isset($item['value'])) {
      $text = check_plain($item['value']);

      // iPhone Support.
      if (strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') !== FALSE) {
        $text = '<a href="tel:' . $text . '">' . $text . '</a>';
      }
    }
    $element[$delta]['#markup'] = $text;
    $element['#attached']['js'][] = drupal_get_path('module', 'international_phone') . '/js/intlTelInput.js';
    $element['#attached']['js'][] = drupal_get_path('module', 'international_phone') . '/js/international_phone.js';
  }
  return $element;
}