function flag_flag::theme in Flag 7.2
Same name and namespace in other branches
- 5 flag.inc \flag_flag::theme()
- 6.2 flag.inc \flag_flag::theme()
- 6 flag.inc \flag_flag::theme()
- 7.3 includes/flag/flag_flag.inc \flag_flag::theme()
Renders a flag/unflag link. This is a wrapper around theme('flag') that, in Drupal 6, easily channels the call to the right template file.
For parameters docmentation, see theme_flag().
File
- ./
flag.inc, line 1282 - Implements various flags. Uses object oriented style inspired by that of Views 2.
Class
- flag_flag
- This abstract class represents a flag, or, in Views 2 terminology, "a handler".
Code
function theme($action, $content_id, $after_flagging = FALSE) {
static $js_added = array();
global $user;
// If the flagging user is anonymous, set a boolean for the benefit of
// JavaScript code. Currently, only our "anti-crawlers" mechanism uses it.
if ($user->uid == 0 && !isset($js_added['anonymous'])) {
$js_added['anonymous'] = TRUE;
drupal_add_js(array(
'flag' => array(
'anonymous' => TRUE,
),
), 'setting');
}
// If the flagging user is anonymous and the page cache is enabled, we
// update the links through JavaScript.
if ($this
->uses_anonymous_cookies() && !$after_flagging) {
if ($this->global) {
// In case of global flags, the JavaScript template is to contain
// the opposite of the current state.
$js_action = $action == 'flag' ? 'unflag' : 'flag';
}
else {
// In case of non-global flags, we always show the "flag!" link,
// and then replace it with the "unflag!" link through JavaScript.
$js_action = 'unflag';
$action = 'flag';
}
if (!isset($js_added[$this->name . '_' . $content_id])) {
$js_added[$this->name . '_' . $content_id] = TRUE;
$js_template = theme($this
->theme_suggestions(), array(
'flag' => $this,
'action' => $js_action,
'content_id' => $content_id,
'after_flagging' => $after_flagging,
));
drupal_add_js(array(
'flag' => array(
'templates' => array(
$this->name . '_' . $content_id => $js_template,
),
),
), 'setting');
}
}
return theme($this
->theme_suggestions(), array(
'flag' => $this,
'action' => $action,
'content_id' => $content_id,
'after_flagging' => $after_flagging,
));
}