使用页面上的节点菜单 [英] Use node-menu on page

查看:133
本文介绍了使用页面上的节点菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Drupal的页面上使用节点菜单(请参阅图像)。

I would like to use the node-menu (see image) on a page in Drupal.

这是可能的,如果是的话,如何?

Is this possible and, if yes, how?

推荐答案

引用是模块的自定义页面输出,mymodule / page是该页面的路径,您需要为其选择查看和编辑,然后应实现 hook_menu() 使用与以下代码相似的代码:

If the page you are referring is a custom page output from your module, and "mymodule/page" is the path for that page, for which you want the tabs "View" and "Edit," then you should implement hook_menu() using code similar to the following one:

function mymodule_menu() {
  $items = array();

  $items['mymodule/page'] = array(
    'page callback' => 'mymodule_page_view', 
    'access arguments' => array('view mymodule page'),
  );

  $items['mymodule/page/view'] = array(
    'title' => 'View', 
    'type' => MENU_DEFAULT_LOCAL_TASK, 
    'weight' => -10,
  );
  $items['mymodule/page/edit'] = array(
    'title' => 'Edit', 
    'page callback' => 'mymodule_page_edit', 
    'access arguments' => array('edit mymodule page'), 
    'weight' => 0, 
    'type' => MENU_LOCAL_TASK, 
  );

  return $items;
}

如果您所引用的页面是example.com上显示的页面/ mymodule / page,那应该显示你在example.com/node/7看到的内容,那么你可以在Drupal 7中实现下面的代码:

If the page you are referring is a page that is shown at example.com/mymodule/page, and that should show what you see at example.com/node/7, then you can implement the following code, in Drupal 7:

function mymodule_url_inbound_alter(&$path, $original_path, $path_language) {
  if (preg_match('|^mymodule/page|', $path)) {
    $path = 'node/7';
  }
}

与Drupal 6相当的是将以下代码写入settings.php文件:

The equivalent for Drupal 6 is writing the following code in the settings.php file:

function custom_url_rewrite_inbound(&$result, $path, $path_language) {
  if (preg_match('|^mymodule/page|', $path)) {
    $result = 'node/7';
  }
}

我没有为 hook_url_outbound_alter() custom_url_rewrite_outbound(),因为我想你不想对example.com/node/7进行重写它显示为example.com/mymodule/page,但您有兴趣将example.com/mymodule/page与example.com/node/7相同。

I didn't write the symmetric code for hook_url_outbound_alter(), and custom_url_rewrite_outbound() as I suppose you are not interested in rewriting example.com/node/7 to make it appear as example.com/mymodule/page, but you are interested in making appear example.com/mymodule/page the same as example.com/node/7.

这篇关于使用页面上的节点菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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