Project

General

Profile

Paste
Download (3.66 KB) Statistics
| Branch: | Revision:

root / drupal7 / sites / all / modules / flag / flag.info.inc @ 4cfd8be6

1
<?php
2

    
3
/**
4
 * @file
5
 * Contains Entity API property information.
6
 */
7

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