2010-06-19 58 views
1

無論如何我可以自定義節點選項卡的路徑嗎?使用自定義路徑創建自定義節點選項卡

當使用pathauto或hook_menu_alter時,我可以將節點視圖的路徑更改爲node/node_id,幾乎可以做任何事情,但讓我們假設xyz/node_title。

節點的標籤,但是,仍然留在路徑/節點/ NODE_ID/TAB_NAME

我想自定義選項卡添加到節點,並保持自定義路徑,以及(如:XYZ/node_title/tab_name而不是node/node_id/tab_name)。

我管理通過hook_menu添加自定義標籤:

$items['node/%node/members'] = array( 
    'title' => 'Manage Membership', 
    'page callback' => 'mymodule_members', 
    'page arguments' => array(1), 
    'access callback' => 'mymembers_members_access', 
    'access arguments' => array(1), 
    'type' => MENU_LOCAL_TASK 
); 

但如果我嘗試定製的道路,無論是在hook_menu或hook_menu_alter,標籤就會消失。

任何想法?

PS,我在Drupal論壇上發佈了the same question,到目前爲止沒有答案。我會交叉更新。

回答

2

您可以在settings.php中添加兩個函數:custom_url_rewrite_inbound()custom_url_rewrite_outbound()

這些頁面中的示例應該明確如何使用它們。

function custom_url_rewrite_inbound(&$result, $path, $path_language) { 
    global $user; 

    // Change all article/x requests to node/x 
    if (preg_match('|^article(/.*)|', $path, $matches)) { 
    $result = 'node'. $matches[1]; 
    } 
    // Redirect a path called 'e' to the user's profile edit page. 
    if ($path == 'e') { 
    $result = 'user/'. $user->uid .'/edit'; 
    } 
} 

function custom_url_rewrite_outbound(&$path, &$options, $original_path) { 
    global $user; 

    // Change all 'node' to 'article'. 
    if (preg_match('|^node(/.*)|', $path, $matches)) { 
    $path = 'article'. $matches[1]; 
    } 
    // Create a path called 'e' which lands the user on her profile edit page. 
    if ($path == 'user/'. $user->uid .'/edit') { 
    $path = 'e'; 
    } 
} 

Drupal 7的使用兩個新的鉤子,而不是那些功能:hook_url_inbound_alter()hook_url_outbound_alter()

+0

我結束了使用這個答案,與url_alter模塊(這使我保持settings.php乾淨)。 subpath_alias模塊與其他自定義代碼進行了拼合。 – Omer 2010-06-20 12:47:38

+0

@kiamlaluno,Drupal 7使用什麼? – Michiel 2012-01-09 13:55:53

+0

@Michiel我更新了我的答案來報告。 – kiamlaluno 2012-01-09 14:26:12