function power_menu_tokens in Power Menu 7
Same name and namespace in other branches
- 7.2 power_menu.tokens.inc \power_menu_tokens()
Implements hook_tokens().
Parameters
$type:
$object:
$options:
File
- ./
power_menu.module, line 604 - This module provides some additional menu features. The features are not actually new, but are part of other modules. it's though very cumbersome to creating a new menu item, because one has to go to all the different places to configure these…
Code
function power_menu_tokens($type, $tokens, $data, $options) {
if ($type == 'node' && !empty($data['node'])) {
$node = $data['node'];
$pms = power_menu_get_pm_menus();
$taxonomy_field = 'field_' . variable_get('power_menu_taxonomy_field', '');
foreach (array_filter($pms) as $pm) {
$mlid = db_query("SELECT mlid FROM {menu_links} WHERE menu_name = :menu_name AND link_path = :link_path", array(
':menu_name' => $pm,
':link_path' => "node/{$node->nid}",
))
->fetchField();
if ($mlid > 0) {
//we have a node that is in the menu
$href = db_query("select ml2.link_path FROM {menu_links} ml INNER JOIN {menu_links} ml2 ON ml.plid = ml2.mlid WHERE ml.mlid = :mlid", array(
':mlid' => $mlid,
))
->fetchField();
}
else {
if (($href = db_query("SELECT path FROM {power_menu} WHERE nodetype = :nodetype AND menu_name = :menu_name", array(
':nodetype' => $node->type,
':menu_name' => $pm,
))
->fetchField()) != '') {
// a node type that belongs to a defined menu entry
}
else {
if (!empty($taxonomy_field) && !empty($node->{$taxonomy_field})) {
// a node that belongs to the taxonomy
$href = _power_menu_get_node_location_taxonomy($node, $pm);
}
}
}
$replacement["[node:power_menu_path_{$pm}-path]"] = $href ? drupal_get_path_alias($href, $node->language) : 'content-default';
}
return $replacement;
}
}