function flag_link in Flag 5
Same name and namespace in other branches
- 6.2 flag.module \flag_link()
- 6 flag.module \flag_link()
- 7.2 flag.module \flag_link()
Implementation of hook_link().
File
- ./
flag.module, line 134 - The Flag module.
Code
function flag_link($type, $object = NULL, $teaser = FALSE) {
if (!isset($object) || !flag_fetch_definition($type)) {
return;
}
global $user;
// Anonymous users can't create flags with this system.
if (!$user->uid) {
return;
}
// Get all possible flags for this content-type.
$flags = flag_get_flags($type);
foreach ($flags as $flag) {
if (!$flag
->user_access($user)) {
// User has no permission to use this flag.
continue;
}
if (!$flag
->uses_hook_link($teaser)) {
// Flag is not configured to show its link here.
continue;
}
if (!$flag
->applies_to_content_object($object)) {
// Flag does not apply to this content.
continue;
}
$content_id = $flag
->get_content_id($object);
// The flag links are actually fully rendered theme functions.
// The HTML attribute is set to TRUE to allow whatever the themer desires.
$links['flag-' . $flag->name] = array(
'title' => $flag
->theme($flag
->is_flagged($content_id) ? 'unflag' : 'flag', $content_id),
'html' => TRUE,
);
}
if (isset($links)) {
return $links;
}
}