You are here

function heartbeat_plugins_tokens in Heartbeat 7

Implements hook_tokens().

File

modules/heartbeat_plugins/heartbeat_plugins.module, line 275

Code

function heartbeat_plugins_tokens($type, $tokens, array $data = array(), array $options = array()) {
  ctools_include('modal');
  ctools_include('ajax');
  $url_options = array(
    'absolute' => TRUE,
  );
  $url_options['alias'] = TRUE;
  if (isset($options['language'])) {
    $url_options['language'] = $options['language'];
    $language_code = $options['language']->language;
  }
  else {
    $language_code = NULL;
  }
  $sanitize = !empty($options['sanitize']);
  $replacements = array();
  if ($type == 'heartbeat_activity' && !empty($data['heartbeat_activity'])) {
    $flags = flag_get_flags('heartbeat_activity');
    $object = $data['heartbeat_activity'];
    foreach ($flags as $flag) {
      $flag_token = 'flag-' . str_replace('_', '-', $flag->name) . '-count-linked';
      foreach ($tokens as $name => $original) {
        if ($name == $flag_token) {
          $count = $flag
            ->get_count($flag
            ->get_content_id($object));
          $output = ctools_modal_text_button($count == 1 ? t('One person') : t('@count people', array(
            '@count' => $count,
          )), 'heartbeat/nojs/flagged/' . $object->uaid, t('Show people'), 'ctools-modal-ctools-heartbeat-style');
          $replacements[$original] = $output;
        }
      }
    }
  }
  return $replacements;
}