MenutrailbypathActivetrail.inc in Menu Trail By Path 7.3
File
src/MenutrailbypathActivetrail.inc
View source
<?php
class MenutrailbypathActivetrail {
protected $pathHelper;
protected $menuHelper;
protected $urlHelper;
public function __construct(MenutrailbypathPathHelper $pathHelper, MenutrailbypathMenuHelper $menuHelper, MenutrailbypathUrlHelper $urlHelper) {
$this->pathHelper = $pathHelper;
$this->menuHelper = $menuHelper;
$this->urlHelper = $urlHelper;
}
public function setActivetrails() {
$menu_names = $this->menuHelper
->getActiveMenuNames();
foreach ($menu_names as $menu_name) {
$this
->setActivetrail($menu_name);
}
}
public function setActivetrail($menu_name) {
$preferred_links =& drupal_static('menu_link_get_preferred');
$path = $_GET['q'];
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');
$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'];
if (!empty($candidate_item['path'])) {
$map = explode('/', $path);
_menu_translate($candidate_item, $map);
}
$preferred_links[$path][$menu_name] = $candidate_item;
}
}
protected function getActiveTrailLink($menu_name) {
$menu_links = array_reverse($this->menuHelper
->getMenuLinks($menu_name));
$trail_paths = array_reverse($this->pathHelper
->getPaths());
foreach ($trail_paths as $trail_path) {
$trail_path_url = $this->urlHelper
->getUrl($trail_path);
foreach ($menu_links as $menu_link) {
if ($menu_link->menu_path_by_trail_url == $trail_path_url) {
return $menu_link;
}
}
}
return NULL;
}
}