2012-02-13 4 views
0

アクティブなトレールが適用された状態で、現在のURLに応じてカスタムメニューをレンダリングするブロックフックを作成するにはどうすればよいですか?キャッシュされているので、通常のメニューではできません。カスタムとは、ユーザーごとに異なるメニュー項目を意味します。ユーザーXさんを見たときDrupalは動的メニューをレンダリングするためのカスタムブロックフックを作成します

例メニューは

|-- User X's profile (active) 
|-- User X's groups 
    |-- Group A 
    |-- Group B 
    |-- Group C 

をプロファイリングしかし、私は設定に移動し、自分のユーザープロファイルを参照した場合、メニューはこの

|-- My profile 
|-- My settings 
    |-- Profile settings (active) 
    |-- Group settings 
|-- My groups 
    |-- Group X 
    |-- Group Y 
    |-- Group Z 
のようになります。このようになります。

これを平易なHTML形式で出力するブロックを作成するのは非常に簡単です。しかし、上記のように、私はリンクに適用されたアクティブトレイルが必要です。また、ハードコードやそれ以外のものではなく、異なるメニューフックからルートを編集したいだけです。

提案がありますか?

答えて

0

私はどこから盗んだのか思い出せませんが、 'your_module_menu_tree_full()'を呼び出すと、アクティブな項目に注釈が付けられた配列ツリーとして名前付きメニューが表示されます。

function your_module_menu_tree_full($menu_name = 'main-menu') { 
    static $menu_output = array(); 
    if (!isset($menu_output[$menu_name])) { 
    $tree = _your_module__menu_find_active_trail(menu_tree_all_data($menu_name)); 
    $menu_output[$menu_name] = menu_tree_output($tree); 
    } 
    return $menu_output[$menu_name]; 
} 

function _your_module__menu_find_active_trail(&$menu_tree) { 
    $item = menu_get_item(); 
    _your_module_menu_find_active_trail($menu_tree, $item); 
    return $menu_tree; 
} 

function _your_module_menu_find_active_trail(&$menu_tree, $item) { 
    $level_is_expanded = FALSE; 
    foreach($menu_tree as &$menu_item) { 
    $link = &$menu_item['link']; 
    if ($link['href']==$item['href']) { // Found the exact location in the tree 
     $link['active'] = TRUE; 
     $link['in_active_trail'] = TRUE; 
     return true; 
    } else { 
     if ($link['has_children']) { 
     $result = _your_module_menu_find_active_trail($menu_item['below'], $item); 
     $link['in_active_trail'] = $result; 
     if ($result) $level_is_expanded = TRUE; 
     } 
    } 
    } 
    return $level_is_expanded; 
} 

試してみてください。

$menu = your_module_menu_tree_full('main-menu'); 
error_log(print_r($menu, TRUE)); 
+0

ああ、私はここからそれを盗んだ:http://www.touchdesk.nl/2009/04/full-menu-tree-with-active-trail-in -drupal-6/:-) –

+0

私は間違いなくこれを試してみます。ありがとう! – hampusohlsson

関連する問題