You are here

function tweet_feed_field_formatter_view in Tweet Feed 7.3

Same name and namespace in other branches
  1. 7.2 tweet_feed.field_info.inc \tweet_feed_field_formatter_view()

Implements hook_field_formatter_view().

File

./tweet_feed.field_info.inc, line 82

Code

function tweet_feed_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = $mentions = array();
  $connection = Database::getConnection();
  $utf8mb4_configurable = $connection
    ->utf8mb4IsConfigurable();
  $utf8mb4_active = $connection
    ->utf8mb4IsActive();
  $utf8mb4_supported = $connection
    ->utf8mb4IsSupported();
  $utf8 = $utf8mb4_configurable && $utf8mb4_active && $utf8mb4_supported ? TRUE : FALSE;
  switch ($display['type']) {

    // Override check plain
    case 'tweet_feed_user_mentions':
      foreach ($items as $delta => $item) {
        $mentions[] = $item['tweet_feed_mention_name'] . ' (' . $item['tweet_feed_mention_screen_name'] . '): ' . $item['tweet_feed_mention_id'];
      }
      if (!empty($delta)) {
        $mentions = implode('<br />', $mentions);
        $element[$delta] = array(
          '#markup' => $mentions,
        );
      }
      break;

    // Give us a way to display emoji.
    case 'emoji_formatter':
      foreach ($items as $delta => $item) {
        if ($utf8 === TRUE) {
          $element[$delta] = array(
            '#markup' => $item['value'],
          );
        }
        else {
          $element[$delta] = array(
            '#markup' => utf8_decode($item['value']),
          );
        }
      }
      break;
  }
  return $element;
}