function menu_views_tokens in Menu Views 8.3
Same name and namespace in other branches
- 7.2 menu_views.module \menu_views_tokens()
- 7 includes/tokens.inc \menu_views_tokens()
Implements hook_tokens().
File
- ./
menu_views.module, line 593 - Module to allow Views to be attached as menu items.
Code
function menu_views_tokens($type, $tokens, array $data = array(), array $options = array()) {
$url_options = array(
'absolute' => TRUE,
);
if (isset($options['language'])) {
$url_options['language'] = $options['language'];
$language_code = $options['language']->language;
}
else {
$language_code = NULL;
}
$sanitize = !empty($options['sanitize']);
$replacements = array();
// Menu link tokens.
if ($type == 'menu-link' && !empty($data['menu-link'])) {
$link = (array) $data['menu-link'];
// menu-link:node tokens.
if ($node_tokens = token_find_with_prefix($tokens, 'node')) {
$node = menu_get_object('node', 1, $link['link_path']);
if (!$node && '<view>' === $link['link_path'] && !empty($link['options']['menu_views']['original_path'])) {
$node = menu_get_object('node', 1, $link['options']['menu_views']['original_path']);
}
if ($node) {
$replacements += token_generate('node', $node_tokens, array(
'node' => $node,
), $options);
}
else {
$replacements += token_generate('node', $node_tokens, array(
'node' => NULL,
), $options);
}
}
elseif (($parent_tokens = token_find_with_prefix($tokens, 'parent')) && !empty($link['plid']) && ($parent = menu_link_load($link['plid']))) {
$node = menu_get_object('node', 1, $parent['link_path']);
if (!$node && '<view>' === $parent['link_path'] && !empty($parent['options']['menu_views']['original_path'])) {
$node = menu_get_object('node', 1, $parent['options']['menu_views']['original_path']);
}
if ($node) {
$replacements += token_generate('node', $parent_tokens, array(
'node' => $node,
), $options);
}
else {
$replacements += token_generate('node', $parent_tokens, array(
'node' => NULL,
), $options);
}
}
}
return $replacements;
}