You are here

function phone_link_view in Phone link 7

Replace phone number with link

Parameters

$item:

Return value

string

1 call to phone_link_view()
phone_link_field_formatter_view in ./phone_link.module
Implements hook_field_formatter_view().

File

./phone_link.module, line 102

Code

function phone_link_view($item, $settings) {
  $phone = $item['value'];

  // Get formatter settings
  $link_title = $settings['title'] ? format_string($settings['title'], array(
    '@phone' => $phone,
  )) : '';
  $link_text = $settings['text'] ? format_string($settings['text'], array(
    '@phone' => $phone,
  )) : $phone;
  $link_type = $settings['type'] ?: 'tel';

  // Remove all non-phone symbols
  $clean_phone = preg_replace('/[^\\d+]/', '', $phone);

  // Add link options
  $options = array(
    'external' => TRUE,
    'attributes' => array(
      'title' => $link_title,
      'class' => array(
        'phone-link',
      ),
    ),
  );
  return l($link_text, "{$link_type}:" . substr($clean_phone, 0, 15), $options);
}