public function MenutrailbypathActivetrail::setActivetrail in Menu Trail By Path 7.3
Set the active trail for the specified menu
Parameters
$menu_name:
1 call to MenutrailbypathActivetrail::setActivetrail()
- MenutrailbypathActivetrail::setActivetrails in src/
MenutrailbypathActivetrail.inc - Set the active trail for all menu's
File
- src/
MenutrailbypathActivetrail.inc, line 35
Class
Code
public function setActivetrail($menu_name) {
// The only way to override the default preferred menu link for a path is to
// inject it into the static cache of the function menu_link_get_preferred().
$preferred_links =& drupal_static('menu_link_get_preferred');
$path = $_GET['q'];
// If the regular menu_link_get_preferred isn't called yet, we need to call it get a
// clean menu_link_get_preferred static cache (and thus avoiding any unpredictable behaviours)
if (!isset($preferred_links[$path][MENU_PREFERRED_LINK])) {
menu_link_get_preferred();
}
if ($menu_link = $this
->getActiveTrailLink($menu_name)) {
$query = db_select('menu_links', 'ml', array(
'fetch' => PDO::FETCH_ASSOC,
));
$query
->leftJoin('menu_router', 'm', 'm.path = ml.router_path');
$query
->fields('ml');
// Weight must be taken from {menu_links}, not {menu_router}.
$query
->addField('ml', 'weight', 'link_weight');
$query
->fields('m');
$query
->condition('ml.mlid', $menu_link->mlid, '=');
$candidate_item = $query
->execute()
->fetchAssoc();
$candidate_item['weight'] = $candidate_item['link_weight'];
// TODO: The menu_links doesn't always have a 1:1 relation to the a menu_router, is it ok to skip the _menu_translate?
if (!empty($candidate_item['path'])) {
$map = explode('/', $path);
_menu_translate($candidate_item, $map);
}
$preferred_links[$path][$menu_name] = $candidate_item;
}
}