-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathflag.actions.inc
More file actions
52 lines (48 loc) · 1.21 KB
/
flag.actions.inc
File metadata and controls
52 lines (48 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/**
* @file
* Callbacks for flag actions.
*/
/**
* Flags an entity.
*
* @param Entity $entity
* The entity object.
* @param array $context
* Context array.
*
* @ingroup actions
*/
function flag_flag_entity_action(&$entity, $context = array()) {
$entity_flags = flag_get_flags($context['action_info']['type']);
$flag_name = $context['action_info']['flag_name'];
$flag = $entity_flags[$flag_name];
$account = isset($context['account']) ? $context['account'] : $GLOBALS['user'];
if (!$flag->is_flagged($entity->id())) {
$flag->flag('flag', $entity->id(), $account, TRUE);
}
else {
return FALSE;
}
}
/**
* Flags an entity.
*
* @param Entity $entity
* The entity object.
* @param array $context
* Context array.
*
* @ingroup actions
*/
function flag_unflag_entity_action(&$entity, $context = array()) {
$entity_flags = flag_get_flags($context['action_info']['type']);
$flag_name = $context['action_info']['flag_name'];
$flag = $entity_flags[$flag_name];
$account = isset($context['account']) ? $context['account'] : $GLOBALS['user'];
if ($flag->is_flagged($entity->id())) {
$flag->flag('unflag', $entity->id(), $account, TRUE);
} else {
return FALSE;
}
}