View source
<?php
function menu_crumbs_plugins($api) {
$api
->multiPlugin('hierarchy');
$api
->multiPlugin('link_title');
}
class menu_CrumbsMultiPlugin_hierarchy implements crumbs_MultiPlugin {
function describe($api) {
return menu_get_menus();
}
function disabledByDefault() {
return array(
'*',
);
}
function findParent($path, $item) {
$q = db_select('menu_links', 'parent');
$q
->innerJoin('menu_links', 'child', 'parent.mlid = child.plid');
$q
->addExpression('parent.link_path', 'parent_path');
$q
->addExpression('parent.menu_name', 'menu_name');
$q
->condition('child.link_path', $path);
$q
->orderBy('parent.depth', 'ASC');
$q
->condition('parent.link_path', array(
'<nolink>',
'<separator>',
), 'NOT IN');
$candidates = array();
foreach ($q
->execute() as $row) {
if (!isset($candidates[$row->menu_name])) {
$candidates[$row->menu_name] = $row->parent_path;
}
}
return $candidates;
}
}
class menu_CrumbsMultiPlugin_link_title implements crumbs_MultiPlugin {
function describe($api) {
return menu_get_menus();
}
function disabledByDefault() {
return array(
'*',
);
}
function findTitle($path, $item) {
$q = db_select('menu_router', 'mr');
$q
->condition('path', $item['path']);
$q
->fields('mr', array(
'title',
));
$router_title = $q
->execute()
->fetchField();
$q = db_select('menu_links', 'ml');
$q
->fields('ml');
$q
->condition('link_path', $path);
$q
->condition('router_path', $item['path']);
$q
->orderBy('ml.depth', 'ASC');
if (module_exists('i18n_menu')) {
$language = LANGUAGE_NONE;
if (isset($GLOBALS['language'])) {
$language = array(
$language,
$GLOBALS['language']->language,
);
$q
->addExpression('ml.language = :language', 'has_language', array(
':language' => LANGUAGE_NONE,
));
$q
->orderBy('has_language');
}
$q
->condition('language', $language);
}
$result = $q
->execute();
$titles = array();
while ($row = $result
->fetchAssoc()) {
if (!isset($titles[$row['menu_name']])) {
$link = $row + $item;
if ($row['link_title'] == $router_title) {
$link['title'] = $item['title'];
}
else {
$link['title'] = $row['link_title'];
}
if (!is_array($link['options'])) {
$link['options'] = unserialize($link['options']);
}
if (1 && module_exists('i18n_menu') && !function_exists('_i18n_menu_link_process')) {
if (1 && isset($link['language']) && $link['language'] === LANGUAGE_NONE) {
unset($link['language']);
}
drupal_alter('translated_menu_link', $link, $item['map']);
$titles[$row['menu_name']] = $link['link_title'];
}
else {
drupal_alter('translated_menu_link', $link, $item['map']);
$titles[$row['menu_name']] = $link['title'];
}
}
}
return $titles;
}
}