使用自定义路径创建自定义节点选项卡 [英] Create a custom node tab with a custom path

查看:195
本文介绍了使用自定义路径创建自定义节点选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当使用pathauto或hook_menu_alter时,我可以将节点视图的路径从节点更改为节点/ node_id到,很多东西,但是让我们说xyz / node_title。



然而,节点选项卡仍然保留路径/ node / node_id / tab_name

我正在尝试向节点添加自定义选项卡,并保持自定义路径(例如:xyz / node_title / tab_name而不是node / node_id / tab_name)。



我设法通过hook_menu添加自定义标签:

  $ item ['node /%node / members'] = array(
'title'=>'Manage Membership',
'page callback'=>'mymodule_members',
'page参数'=>数组(1),
'访问回调'=>'mymembers_members_access',
'访问参数'=>数组(1),
'type'=> ; MENU_LOCAL_TASK
);

但是,如果我尝试自定义路径,无论是在hook_menu还是在hook_menu_alter,标签都会消失。



任何想法?



PS,我发贴了同样的问题在Drupal论坛上,至今没有回答。我会交叉更新。

解决方案

您可以在settings.php中添加两个函数: custom_url_rewrite_inbound() custom_url_rewrite_outbound()



这些页面中的示例应该清楚如何使用它们。 >

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

//将所有文章/ x请求更改为node / x
if(preg_match('| ^ article(/.*)|',$ path,$ matches)){
$ result ='node'。 $匹配[1];
}
//将一个名为'e'的路径重定向到用户的个人资料编辑页面。
if($ path =='e'){
$ result ='user /'。 $ user-> uid。'/ edit';
}
}

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

//将所有节点更改为文章。
if(preg_match('| ^ node(/.*)|',$ path,$ matches)){
$ path ='article'。 $匹配[1];
}
//创建一个名为'e'的路径,将用户登录在她的个人资料编辑页面上。
if($ path =='user /'。$ user-> uid。'/ edit'){
$ path ='e'
}
}

Drupal 7使用两个新的钩子,而不是那些功能: hook_url_inbound_alter() hook_url_outbound_alter()


Is there anyway I can customize the paths to a node's tabs?

When using either pathauto or hook_menu_alter, I can change the path to the node view to from node/node_id to, well pretty much anything, but let's say xyz/node_title.

The node tabs, however, still stay with the path /node/node_id/tab_name

I'm trying to add a custom tab to the node, and keep the custom path as well (e.g.: xyz/node_title/tab_name instead of node/node_id/tab_name).

I manage to add the custom tab via 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  
); 

but if I try to customize the path, either at hook_menu or at hook_menu_alter, the tab just disappears.

Any ideas?

PS, I've posted the same question on the Drupal forums, no answer so far. I'll cross-update.

解决方案

You can add two functions in settings.php: custom_url_rewrite_inbound(), and custom_url_rewrite_outbound().

The examples in those pages should make clear how to use them.

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 uses two new hooks, instead of those functions: hook_url_inbound_alter() and hook_url_outbound_alter().

这篇关于使用自定义路径创建自定义节点选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆