Révision b08d2851
Ajouté par Assos Assos il y a environ 10 ans
drupal7/sites/all/modules/flag/flag.tokens.inc | ||
---|---|---|
7 | 7 |
|
8 | 8 |
/** |
9 | 9 |
* Implements of hook_token_info(). |
10 |
* |
|
11 |
* The tokens we provide on generic entities require token module. |
|
10 | 12 |
*/ |
11 | 13 |
function flag_token_info() { |
12 | 14 |
$types = array(); |
... | ... | |
74 | 76 |
'description' => t('The current count total for this flag.'), |
75 | 77 |
); |
76 | 78 |
|
77 |
// Add tokens for the flag count available at the node/comment/user level. |
|
78 |
foreach (flag_get_types() as $flag_type) { |
|
79 |
$flags = flag_get_flags($flag_type); |
|
80 |
foreach ($flags as $flag) { |
|
81 |
$tokens[$flag_type]['flag-' . str_replace('_', '-', $flag->name) . '-count'] = array( |
|
82 |
'name' => t('@flag flag count', array('@flag' => $flag->get_title())), |
|
83 |
'description' => t('Total flag count for flag @flag', array('@flag' => $flag->get_title())), |
|
84 |
); |
|
85 |
$tokens[$flag_type]['flag-' . str_replace('_', '-', $flag->name) . '-link'] = array( |
|
86 |
'name' => t('@flag flag link', array('@flag' => $flag->get_title())), |
|
87 |
'description' => t('Flag/unflag link for @flag', array('@flag' => $flag->get_title())), |
|
88 |
); |
|
79 |
// Add tokens for the flag count available at the entity level. |
|
80 |
// These require token module because we need its helper data and functions |
|
81 |
// to deal with token types that are not the same as the entity types they are |
|
82 |
// for (in particular, terms and vocabularies). |
|
83 |
if (module_exists('token')) { |
|
84 |
$entity_info = entity_get_info(); |
|
85 |
foreach (flag_get_types() as $flag_type) { |
|
86 |
// The flag type is the entity type, but this is not necessarily the same |
|
87 |
// as the entity's token type. |
|
88 |
$token_type = $entity_info[$flag_type]['token type']; |
|
89 |
$flags = flag_get_flags($flag_type); |
|
90 |
foreach ($flags as $flag) { |
|
91 |
$tokens[$token_type]['flag-' . str_replace('_', '-', $flag->name) . '-count'] = array( |
|
92 |
'name' => t('@flag flag count', array('@flag' => $flag->get_title())), |
|
93 |
'description' => t('Total flag count for flag @flag', array('@flag' => $flag->get_title())), |
|
94 |
'flag-type' => $flag_type, |
|
95 |
); |
|
96 |
$tokens[$token_type]['flag-' . str_replace('_', '-', $flag->name) . '-link'] = array( |
|
97 |
'name' => t('@flag flag link', array('@flag' => $flag->get_title())), |
|
98 |
'description' => t('Flag/unflag link for @flag', array('@flag' => $flag->get_title())), |
|
99 |
'flag-type' => $flag_type, |
|
100 |
); |
|
101 |
} |
|
89 | 102 |
} |
90 | 103 |
} |
91 | 104 |
|
... | ... | |
155 | 168 |
} |
156 | 169 |
} |
157 | 170 |
|
158 |
if (isset($data[$type]) && in_array($type, flag_get_types())) { |
|
159 |
$flags = flag_get_flags($type); |
|
160 |
$object = $data[$type]; |
|
161 |
foreach ($flags as $flag) { |
|
162 |
foreach ($tokens as $name => $original) { |
|
163 |
$flag_count_token = 'flag-' . str_replace('_', '-', $flag->name) . '-count'; |
|
164 |
$flag_link_token = 'flag-' . str_replace('_', '-', $flag->name) . '-link'; |
|
165 |
if ($name == $flag_count_token) { |
|
166 |
$replacements[$original] = $flag->get_count($flag->get_entity_id($object)); |
|
167 |
} |
|
168 |
elseif ($name == $flag_link_token) { |
|
169 |
$replacements[$original] = flag_create_link($flag->name, $flag->get_entity_id($object)); |
|
171 |
// We only provide tokens on entity types if we have token module's helper |
|
172 |
// methods available. |
|
173 |
if (isset($data[$type]) && module_exists('token')) { |
|
174 |
$entity_type = token_get_entity_mapping('token', $type); |
|
175 |
if ($entity_type && in_array($entity_type, flag_get_types())) { |
|
176 |
$flags = flag_get_flags($entity_type); |
|
177 |
$object = $data[$type]; |
|
178 |
foreach ($flags as $flag) { |
|
179 |
foreach ($tokens as $name => $original) { |
|
180 |
$flag_count_token = 'flag-' . str_replace('_', '-', $flag->name) . '-count'; |
|
181 |
$flag_link_token = 'flag-' . str_replace('_', '-', $flag->name) . '-link'; |
|
182 |
if ($name == $flag_count_token) { |
|
183 |
$replacements[$original] = $flag->get_count($flag->get_entity_id($object)); |
|
184 |
} |
|
185 |
elseif ($name == $flag_link_token) { |
|
186 |
$replacements[$original] = flag_create_link($flag->name, $flag->get_entity_id($object)); |
|
187 |
} |
|
170 | 188 |
} |
171 | 189 |
} |
172 | 190 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules