Skip to content
Snippets Groups Projects
Commit 44a8be18 authored by Tim Steiner's avatar Tim Steiner
Browse files

[gh-206] Merging from testing into staging

git-svn-id: file:///tmp/wdn_thm_drupal/branches/drupal-7.x/staging@1058 20a16fea-79d4-4915-8869-1ea9d5ebf173
parent 4fdaa2da
No related branches found
No related tags found
No related merge requests found
...@@ -12,12 +12,22 @@ function unl_html_head_alter(&$head_elements) { ...@@ -12,12 +12,22 @@ function unl_html_head_alter(&$head_elements) {
return; return;
} }
} }
// If we are in a drilled down menu, change the home link to the drilled down item.
$current_menu_link = _unl_get_current_menu_link();
if ($current_menu_link && $current_menu_link->depth > 1) {
$home_path = drupal_get_path_alias($current_menu_link->link_path);
}
else {
$home_path = '<front>';
}
// ...otherwise add a <link rel="home"> tag with the front page as the href attribute // ...otherwise add a <link rel="home"> tag with the front page as the href attribute
$element = array( $element = array(
'#tag' => 'link', '#tag' => 'link',
'#attributes' => array( '#attributes' => array(
'rel' => 'home', 'rel' => 'home',
'href' => url('<front>', array('absolute' => TRUE)), 'href' => url($home_path, array('absolute' => TRUE)),
), ),
'#type' => 'html_tag' '#type' => 'html_tag'
); );
...@@ -1038,3 +1048,101 @@ function _unl_imce_file_browser_access() { ...@@ -1038,3 +1048,101 @@ function _unl_imce_file_browser_access() {
$profile = imce_user_profile($user); $profile = imce_user_profile($user);
return $profile['usertab']; return $profile['usertab'];
} }
/**
* Implements hook_block_view_alter()
* @param array $data
* @param stdClass $block
*/
function unl_block_view_alter(&$data, $block) {
if ($block->module == 'system' && $block->delta == 'main-menu') {
return unl_block_view_system_main_menu_alter($data, $block);
}
}
/**
* Tries to implement hook_block_view_MODULE_DELTA_alter, but since the delta contains a -,
* this is actually called from unl_block_view_alter() for now.
* Used to determin if a "sub-menu" should be used instead of the normal menu.
* @param array $data
* @param stdClass $block
*/
function unl_block_view_system_main_menu_alter(&$data, $block) {
$current_menu_link = _unl_get_current_menu_link();
$submenu = _unl_get_current_submenu($data['content'], $current_menu_link->mlid);
if ($submenu && $submenu['#original_link']['depth'] > 1) {
$data['content'] = $submenu['#below'];
}
$data['content'] = _unl_limit_menu_depth($data['content'], 2);
}
/**
* Return the mlid of the currently selected menu item.
* If the current page has no menu item, use return the mlid of its parent instead.
*/
function _unl_get_current_menu_link() {
$result = db_select('menu_links')
->fields('menu_links')
->condition('menu_name', 'main-menu')
->condition('link_path', current_path())
->execute()
->fetch();
if (!$result) {
return FALSE;
}
while (($result->hidden || $result->depth % 2 !== 0 || !$result->has_children) && $result->depth > 1) {
$result = db_select('menu_links')
->fields('menu_links')
->condition('menu_name', 'main-menu')
->condition('mlid', $result->plid)
->execute()
->fetch();
}
return $result;
}
/**
* Find the the submenu we are currently "drilled-down" to.
* @param array $menu_links
* @param int $current_mlid
*/
function _unl_get_current_submenu($menu_links, $current_mlid) {
foreach (element_children($menu_links) as $index) {
$menu_item = $menu_links[$index];
if ($menu_item['#original_link']['mlid'] == $current_mlid) {
return $menu_item;
}
$sub_menu = _unl_get_current_submenu($menu_item['#below'], $current_mlid);
if ($sub_menu) {
return $sub_menu;
}
}
return FALSE;
}
/**
* Remove any menu items that are more than $depth levels below the current root.
* @param array $menu_links
* @param int $depth
*/
function _unl_limit_menu_depth($menu_links, $depth) {
if ($depth == 0) {
return array();
}
foreach (element_children($menu_links) as $index) {
$menu_links[$index]['#below'] = _unl_limit_menu_depth($menu_links[$index]['#below'], $depth - 1);
}
return $menu_links;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment