function node_gallery_api_tokens in Node Gallery 7
Implements hook_tokens().
File
- ./
node_gallery_api.module, line 505 - Node Gallery module.
Code
function node_gallery_api_tokens($type, $tokens, array $data = array(), array $options = array()) {
$replacements = array();
if ($type == 'node' && !empty($data['node'])) {
$node = $data['node'];
$relationships = node_gallery_api_get_relationships(NULL, $node->nid);
if (!empty($relationships)) {
$r = reset($relationships);
$gallery_node = node_load($r->ngid);
if (!empty($gallery_node)) {
$gallery_path = drupal_get_path_alias('node/' . $gallery_node->nid);
$gallery_title = $gallery_node->title;
$gallery_nid = $gallery_node->nid;
}
else {
$gallery_path = '';
$gallery_title = '';
$gallery_nid = '';
}
foreach ($tokens as $name => $original) {
switch ($name) {
case 'node_gallery_gallery_path':
$replacements[$original] = decode_entities(check_plain($gallery_path));
break;
case 'node_gallery_gallery_title':
$replacements[$original] = decode_entities(check_plain($gallery_title));
break;
case 'node_gallery_gallery_nid':
$replacements[$original] = $gallery_nid;
break;
}
}
}
}
return $replacements;
}