You are here

function skype_field_formatter_view in Skype 7

Implements hook_field_formatter_view().

File

./skype.module, line 215

Code

function skype_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  $settings = $display['settings'];
  switch ($display['type']) {
    case 'skype_button':

      // Determine protocol en lib.
      $lib = 'http://www.skypeassets.com/i/scom/js/skype-uri.js';
      if (stripos($_SERVER['SERVER_PROTOCOL'], 'https') === TRUE) {
        $lib = 'https://secure.skypeassets.com/i/scom/js/skype-uri.js';
      }

      // Render button.
      foreach ($items as $delta => $item) {
        $element[$delta] = array(
          '#theme' => 'skype_button',
          '#skype_id' => $item['skype_id'],
          '#settings' => $settings,
          '#attached' => array(
            'js' => array(
              array(
                'data' => $lib,
                'type' => 'external',
              ),
            ),
          ),
        );
      }
      break;
    case 'skype_uri':

      // Render URI.
      foreach ($items as $delta => $item) {
        $element[$delta] = array(
          '#theme' => 'skype_uri',
          '#skype_id' => $item['skype_id'],
          '#settings' => $settings,
        );
      }
      break;
  }
  return $element;
}