You are here

function international_phone_field_formatter_view in International Phone Field 7.2

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

Implements hook_field_formatter_view().

File

./international_phone.module, line 49
Defines a field for attaching international phone fields to entities.

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']['libraries_load'][] = array(
      'intl-tel-input',
    );
    $element['#attached']['js'][] = array(
      'type' => 'setting',
      'data' => array(
        'internationalPhone' => array(
          'utilsScriptPath' => libraries_get_path('intl-tel-input') . '/build/js/utils.js',
          'defaultCountryCode' => $instance->settings->international_phone_default_country_code,
        ),
      ),
    );
    $element['#attached']['js'][] = array(
      'type' => 'file',
      'data' => drupal_get_path('module', 'international_phone') . '/js/international_phone.js',
    );
  }
  return $element;
}