View source
<?php
class crumbs_TrailFinder {
protected $parentFinder;
protected $router;
function __construct($parent_finder, $router) {
$this->parentFinder = $parent_finder;
$this->router = $router;
}
function getForPath($path) {
return $this
->buildTrail($path);
}
function buildTrail($path) {
$path = $this->router
->getNormalPath($path);
$trail_reverse = array();
$front_normal_path = $this->router
->getFrontNormalPath();
while (strlen($path) && $path !== '<front>' && $path !== $front_normal_path) {
if (isset($trail_reverse[$path])) {
while (isset($trail_reverse[$path])) {
array_pop($trail_reverse);
}
break;
}
$item = $this->router
->getRouterItem($path);
if ($item && $item['type'] & MENU_LINKS_TO_PARENT) {
$path = $item['tab_parent_href'];
$item = $this->router
->getRouterItem($item['tab_parent_href']);
}
if ($item && $item['access']) {
$trail_reverse[$path] = $item;
}
$parent_path = $this->parentFinder
->getParentPath($path, $item);
if ($parent_path === $path) {
break;
}
$path = $parent_path;
}
unset($trail_reverse['<front>']);
$front_menu_item = $this->router
->getRouterItem($front_normal_path);
if (isset($front_menu_item)) {
$front_menu_item['href'] = '<front>';
$trail_reverse[$front_normal_path] = $front_menu_item;
}
else {
$message_raw = 'Your current setting for !site_frontpage seems to be invalid.';
$message_replacements = array(
'!site_frontpage' => '<em>' . l(t('Default front page'), 'admin/config/system/site-information') . '</em>',
);
watchdog('crumbs', $message_raw, $message_replacements);
if (user_access('administer site configuration')) {
drupal_set_message(t($message_raw, $message_replacements), 'warning');
}
}
return array_reverse($trail_reverse);
}
}