-
Notifications
You must be signed in to change notification settings - Fork 11
/
flag.flag.inc
110 lines (102 loc) · 3.34 KB
/
flag.flag.inc
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
/**
* @file
* Contains implementations of flag info hooks.
*/
/**
* Implements hook_flag_type_info().
*
* Defines the flag types this module implements.
*
* @return
* An "array of arrays", keyed by object type. The 'handler' slot
* should point to the PHP class implementing this flag.
*/
function flag_flag_type_info() {
// Entity types we specifically cater for.
$definitions = array(
'node' => array(
'title' => t('Nodes'),
'description' => t("Nodes are a Backdrop CMS site's primary content."),
'handler' => 'flag_node',
),
'user' => array(
'title' => t('Users'),
'description' => t('Users who have created accounts on your site.'),
'handler' => 'flag_user',
),
);
if (module_exists('comment')) {
$definitions['comment'] = array(
'title' => t('Comments'),
'description' => t('Comments are responses to node content.'),
'handler' => 'flag_comment',
'module' => 'comment',
);
}
if (module_exists('taxonomy')) {
$definitions['taxonomy_term'] = array(
'title' => t('Taxonomy Terms'),
'description' => t('Taxonomy terms are used to categorize content.'),
'handler' => 'flag_entity',
'module' => 'taxonomy',
);
}
return $definitions;
}
/**
* Implements hook_flag_type_info_alter().
*
* Step in and add flag types for any entities not yet catered for, using the
* basic flag_entity handler. This allows other modules to provide more
* specialized handlers for entities in hook_flag_type_info() as normal.
*/
function flag_flag_type_info_alter(&$definitions) {
foreach (entity_get_info() as $entity_type => $entity_info) {
// Only add flag support for entities that don't yet have them, and which
// are non-config entities.
if (!isset($definitions[$entity_type]) && empty($entity_info['configuration'])) {
// We deliberately exclude taxonomy vocabularies from the list of
// supported entity types because they aren't fieldable or directly
// viewable, which makes them impossible to flag.
if ($entity_type === 'taxonomy_vocabulary') {
continue;
}
$definitions[$entity_type] = array(
'title' => $entity_info['label'],
'description' => t('@entity-type entity', array('@entity-type' => $entity_info['label'])),
'handler' => 'flag_entity',
);
}
}
}
/**
* Implements hook_flag_link_type_info().
*/
function flag_flag_link_type_info() {
return array(
'toggle' => array(
'title' => t('JavaScript toggle'),
'description' => t('An AJAX request will be made and degrades to type "Normal link" if JavaScript is not available.'),
'uses standard js' => TRUE,
'uses standard css' => TRUE,
),
'normal' => array(
'title' => t('Normal link'),
'description' => t('A normal non-JavaScript request will be made and the current page will be reloaded.'),
'uses standard js' => FALSE,
'uses standard css' => FALSE,
),
'confirm' => array(
'title' => t('Confirmation form'),
'description' => t('The user will be taken to a confirmation form on a separate page to confirm the flag.'),
'options' => array(
'flag_confirmation' => '',
'unflag_confirmation' => '',
),
'uses standard js' => FALSE,
'uses standard css' => FALSE,
'provides form' => TRUE,
),
);
}