1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Contains implementations of flag info hooks.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Implements hook_flag_type_info().
|
10
|
*
|
11
|
* Defines the flag types this module implements.
|
12
|
*
|
13
|
* @return
|
14
|
* An "array of arrays", keyed by object type. The 'handler' slot
|
15
|
* should point to the PHP class implementing this flag.
|
16
|
*/
|
17
|
function flag_flag_type_info() {
|
18
|
// Entity types we specifically cater for.
|
19
|
$definitions = array(
|
20
|
'node' => array(
|
21
|
'title' => t('Nodes'),
|
22
|
'description' => t("Nodes are a Drupal site's primary content."),
|
23
|
'handler' => 'flag_node',
|
24
|
),
|
25
|
'user' => array(
|
26
|
'title' => t('Users'),
|
27
|
'description' => t('Users who have created accounts on your site.'),
|
28
|
'handler' => 'flag_user',
|
29
|
),
|
30
|
);
|
31
|
|
32
|
if (module_exists('comment')) {
|
33
|
$definitions['comment'] = array(
|
34
|
'title' => t('Comments'),
|
35
|
'description' => t('Comments are responses to node content.'),
|
36
|
'handler' => 'flag_comment',
|
37
|
'module' => 'comment',
|
38
|
);
|
39
|
}
|
40
|
|
41
|
if (module_exists('taxonomy')) {
|
42
|
$definitions['taxonomy_term'] = array(
|
43
|
'title' => t('Taxonomy Terms'),
|
44
|
'description' => t('Taxonomy terms are used to categorize content.'),
|
45
|
'handler' => 'flag_entity',
|
46
|
'module' => 'taxonomy',
|
47
|
);
|
48
|
}
|
49
|
|
50
|
return $definitions;
|
51
|
}
|
52
|
|
53
|
/**
|
54
|
* Implements hook_flag_type_info_alter().
|
55
|
*
|
56
|
* Step in and add flag types for any entities not yet catered for, using the
|
57
|
* basic flag_entity handler. This allows other modules to provide more
|
58
|
* specialized handlers for entities in hook_flag_type_info() as normal.
|
59
|
*/
|
60
|
function flag_flag_type_info_alter(&$definitions) {
|
61
|
foreach (entity_get_info() as $entity_type => $entity_info) {
|
62
|
// Only add flag support for entities that don't yet have them, and which
|
63
|
// are non-config entities.
|
64
|
if (!isset($definitions[$entity_type]) && empty($entity_info['configuration'])) {
|
65
|
// We deliberately exclude taxonomy vocabularies from the list of
|
66
|
// supported entity types because they aren't fieldable or directly
|
67
|
// viewable, which makes them impossible to flag.
|
68
|
if ($entity_type === 'taxonomy_vocabulary') {
|
69
|
continue;
|
70
|
}
|
71
|
|
72
|
$definitions[$entity_type] = array(
|
73
|
'title' => $entity_info['label'],
|
74
|
'description' => t('@entity-type entity', array('@entity-type' => $entity_info['label'])),
|
75
|
'handler' => 'flag_entity',
|
76
|
);
|
77
|
}
|
78
|
}
|
79
|
}
|
80
|
|
81
|
/**
|
82
|
* Implements hook_flag_link_type_info().
|
83
|
*/
|
84
|
function flag_flag_link_type_info() {
|
85
|
return array(
|
86
|
'toggle' => array(
|
87
|
'title' => t('JavaScript toggle'),
|
88
|
'description' => t('An AJAX request will be made and degrades to type "Normal link" if JavaScript is not available.'),
|
89
|
'uses standard js' => TRUE,
|
90
|
'uses standard css' => TRUE,
|
91
|
),
|
92
|
'normal' => array(
|
93
|
'title' => t('Normal link'),
|
94
|
'description' => t('A normal non-JavaScript request will be made and the current page will be reloaded.'),
|
95
|
'uses standard js' => FALSE,
|
96
|
'uses standard css' => FALSE,
|
97
|
),
|
98
|
'confirm' => array(
|
99
|
'title' => t('Confirmation form'),
|
100
|
'description' => t('The user will be taken to a confirmation form on a separate page to confirm the flag.'),
|
101
|
'options' => array(
|
102
|
'flag_confirmation' => '',
|
103
|
'unflag_confirmation' => '',
|
104
|
),
|
105
|
'uses standard js' => FALSE,
|
106
|
'uses standard css' => FALSE,
|
107
|
'provides form' => TRUE,
|
108
|
),
|
109
|
);
|
110
|
}
|