You are here

function template_preprocess_flag in Flag 6

Same name and namespace in other branches
  1. 5 flag.module \template_preprocess_flag()
  2. 6.2 flag.module \template_preprocess_flag()
  3. 7.3 flag.module \template_preprocess_flag()
  4. 7.2 flag.module \template_preprocess_flag()

A preprocess function for our theme('flag'). It generates the variables needed there.

The $variables array initially contains the following arguments:

  • $flag
  • $action
  • $content_id
  • $after_flagging

See 'flag.tpl.php' for their documentation.

Note: The Drupal 5 version of this module calls this function directly.

File

./flag.module, line 678

Code

function template_preprocess_flag(&$variables) {
  static $first_time = TRUE;

  // Some typing shotcuts:
  $flag =& $variables['flag'];
  $action = $variables['action'];
  $content_id = $variables['content_id'];

  // Generate the link URL.
  $link_types = flag_get_link_types();
  $link_type_module = $link_types[$flag->link_type]['module'];
  $link = module_invoke($link_type_module, 'flag_link', $flag, $action, $content_id);
  if (isset($link['title']) && empty($link['html'])) {
    $link['title'] = check_plain($link['title']);
  }
  if ($flag->link_type == 'toggle' && $first_time) {
    $variables['setup'] = $first_time;
    $first_time = FALSE;
  }
  else {
    $variables['setup'] = FALSE;
  }
  $variables['link_href'] = check_url(url($link['href'], $link));
  $variables['link_text'] = isset($link['title']) ? $link['title'] : $flag
    ->get_label($action . '_short', $content_id);
  $variables['link_title'] = isset($link['attributes']['title']) ? check_plain($link['attributes']['title']) : check_plain(strip_tags($flag
    ->get_label($action . '_long', $content_id)));
  $variables['flag_name_css'] = str_replace('_', '-', $flag->name);
  $variables['last_action'] = $action == 'flag' ? 'unflagged' : 'flagged';
  $variables['flag_classes_array'] = array();
  $variables['flag_classes_array'][] = 'flag';
  $variables['flag_classes_array'][] = $variables['action'] . '-action';
  $variables['flag_classes_array'][] = 'flag-link-' . $flag->link_type;
  if (isset($link['attributes']['class'])) {
    $variables['flag_classes_array'][] = $link['attributes']['class'];
  }
  if ($variables['after_flagging']) {
    $inverse_action = $action == 'flag' ? 'unflag' : 'flag';
    $variables['message_text'] = $flag
      ->get_label($inverse_action . '_message', $content_id);
    $variables['flag_classes_array'][] = $variables['last_action'];
  }
  $variables['flag_classes'] = implode(' ', $variables['flag_classes_array']);
}