1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file Contains Entity API property information.
|
5
|
*/
|
6
|
|
7
|
/**
|
8
|
* Implements hook_entity_property_info_alter().
|
9
|
*
|
10
|
* We add properties thus:
|
11
|
* - global flags:
|
12
|
* - entity->flag_FLAGNAME, boolean.
|
13
|
* - per-user flags:
|
14
|
* - entity->flag_FLAGNAME_users, list of users.
|
15
|
* - user->flag_FLAGNAME_flagged, list of user's flagged entities.
|
16
|
*/
|
17
|
function flag_entity_property_info_alter(&$info) {
|
18
|
foreach (flag_get_flags() as $flag) {
|
19
|
if ($flag->global) {
|
20
|
// Global flags.
|
21
|
// Boolean property on entity type.
|
22
|
// This can go on either the entity as a whole, or on bundles, depending
|
23
|
// on whether the flag is limited by bundle.
|
24
|
$property_definition = array(
|
25
|
'label' => t('Whether the entity is flagged with flag @flag', array(
|
26
|
'@flag' => $flag->name,
|
27
|
)),
|
28
|
'description' => t('Whether the entity is flagged with flag @flag.', array(
|
29
|
'@flag' => $flag->name,
|
30
|
)),
|
31
|
'type' => 'boolean',
|
32
|
'getter callback' => 'flag_properties_get_flagging_boolean',
|
33
|
'computed' => TRUE,
|
34
|
'flag_name' => $flag->name,
|
35
|
);
|
36
|
if (count($flag->types)) {
|
37
|
// Bundle specific property.
|
38
|
foreach ($flag->types as $type) {
|
39
|
$info[$flag->entity_type]['bundles'][$type]['properties']['flag_' . $flag->name] = $property_definition;
|
40
|
}
|
41
|
}
|
42
|
else {
|
43
|
// Generic property, applies for all bundles.
|
44
|
$info[$flag->entity_type]['properties']['flag_' . $flag->name] = $property_definition;
|
45
|
}
|
46
|
}
|
47
|
else {
|
48
|
// Per-user flags.
|
49
|
// User property: list of flagged entities by the user.
|
50
|
$info['user']['properties']['flag_' . $flag->name . '_flagged'] = array(
|
51
|
'label' => t('Flagged @entity-type with flag @flag', array(
|
52
|
'@entity-type' => $flag->entity_type,
|
53
|
'@flag' => $flag->name,
|
54
|
)),
|
55
|
'description' => t('Returns a list of entities a user flagged with flag @flag.', array(
|
56
|
'@flag' => $flag->name,
|
57
|
)),
|
58
|
'type' => 'list<' . $flag->entity_type . '>',
|
59
|
'getter callback' => 'flag_properties_get_flagged_entities',
|
60
|
'computed' => TRUE,
|
61
|
'flag_name' => $flag->name,
|
62
|
'flag_entity_type' => $flag->entity_type,
|
63
|
);
|
64
|
$info['user']['properties']['flag_sid'] = array(
|
65
|
'label' => t('Flag user session identifier'),
|
66
|
'description' => t('Returns the sessions id used to distinguish anonymous users from each other.'),
|
67
|
'type' => 'text',
|
68
|
'getter callback' => 'flag_properties_get_user_sid',
|
69
|
'computed' => TRUE,
|
70
|
);
|
71
|
// Entity property: list of users who have flagged this entity.
|
72
|
// This can go on either the entity as a whole, or on bundles, depending
|
73
|
// on whether the flag is limited by bundle.
|
74
|
$property_definition = array(
|
75
|
'label' => t('Users who flagged the entity with flag @flag', array(
|
76
|
'@flag' => $flag->name,
|
77
|
)),
|
78
|
'description' => t('Returns a list of users who flagged an entity with flag @flag.', array(
|
79
|
'@flag' => $flag->name,
|
80
|
)),
|
81
|
'type' => 'list<user>',
|
82
|
'getter callback' => 'flag_properties_get_flagging_users',
|
83
|
'computed' => TRUE,
|
84
|
'flag_name' => $flag->name,
|
85
|
);
|
86
|
if (count($flag->types)) {
|
87
|
// Bundle specific property.
|
88
|
foreach ($flag->types as $type) {
|
89
|
$info[$flag->entity_type]['bundles'][$type]['properties']['flag_' . $flag->name . '_user'] = $property_definition;
|
90
|
}
|
91
|
}
|
92
|
else {
|
93
|
// Generic property, applies for all bundles.
|
94
|
$info[$flag->entity_type]['properties']['flag_' . $flag->name . '_user'] = $property_definition;
|
95
|
}
|
96
|
}
|
97
|
}
|
98
|
}
|