menu_set_location

Хочешь помочь с переводом? Это очень просто и быстро. Лишь зарегистрируйся, и можешь тут же начать переводить.

includes/menu.inc, строка 325

Версии
5
menu_set_location($location)

Change the current menu location of the user.

Frequently, modules may want to make a page or node act as if it were in the menu tree somewhere, even though it was not registered in a hook_menu() implementation. If the administrator has rearranged the menu, the newly set location should respect this in the breadcrumb trail and expanded/collapsed status of menu items in the tree. This function allows this behavior.

This function will set the new breadcrumb trail to the passed-in value, but if any elements of this trail are visible in the site tree, the trail will be 'spliced in' to the existing site navigation at that point.

Параметры

$location An array specifying a complete or partial breadcrumb trail for the new location, in the same format as the return value of hook_menu(). The last element of this array should be the new location itself.

Связанные темы

▾ 7 функции вызывают menu_set_location()

blog_view in modules/blog/blog.module
Реализация hook_view().
book_nodeapi in modules/book/book.module
Implementation of hook_nodeapi().
comment_reply in modules/comment/comment.module
This function is responsible for generating a comment reply form. There are several cases that have to be handled, including: replies to comments replies to nodes attempts to reply to nodes that can no longer accept comments respecting access...
forum_view in modules/forum/forum.module
Реализация hook_view().
hook_view in developer/hooks/node.php
Показывает ноду.
taxonomy_term_page in modules/taxonomy/taxonomy.module
Menu callback; displays all nodes associated with a term.
theme_forum_display in modules/forum/forum.module
Format the forum body.

Код

<?php
function menu_set_location($location) {
  global $_menu;
  $temp_id = min(array_keys($_menu['items'])) - 1;
  $prev_id = 0;

  // Don't allow this function to change the actual current path, just the
  // position in the menu tree.
  $location[count($location) - 1]['path'] = $_GET['q'];

  foreach (array_reverse($location) as $item) {
    if (isset($_menu['path index'][$item['path']])) {
      $mid = $_menu['path index'][$item['path']];
      if (isset($_menu['visible'][$mid])) {
        // Splice in the breadcrumb at this location.
        if ($prev_id) {
          $_menu['items'][$prev_id]['pid'] = $mid;
        }
        $prev_id = 0;
        break;
      }
      else {
        // A hidden item; show it, but only temporarily.
        $_menu['items'][$mid]['type'] |= MENU_VISIBLE_IN_BREADCRUMB;
        if ($prev_id) {
          $_menu['items'][$prev_id]['pid'] = $mid;
        }
        $prev_id = $mid;
      }
    }
    else {
      $item['type'] |= MENU_VISIBLE_IN_BREADCRUMB;
      if ($prev_id) {
        $_menu['items'][$prev_id]['pid'] = $temp_id;
      }
      $_menu['items'][$temp_id] = $item;
      $_menu['path index'][$item['path']] = $temp_id;

      $prev_id = $temp_id;
      $temp_id--;
    }
  }

  if ($prev_id) {
    // Didn't find a home, so attach this to the main navigation menu.
    $_menu['items'][$prev_id]['pid'] = 1;
  }

  $final_item = array_pop($location);
  menu_set_active_item($final_item['path']);
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии

Вход в систему