Drupal用户配置文件页面中的自定义菜单选项卡 [英] Custom Menu tabs in Drupal user profile page

查看:166
本文介绍了Drupal用户配置文件页面中的自定义菜单选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在用户个人资料页面顶部的[view] [edit] [files] ...菜单链接旁添加一个菜单项。当用户点击它时,它应该像其他人一样行事,因为它不只是启动到一个新的页面,而是他们点击的菜单项(让我们称之为Funky Button)变灰,用户保持在用户个人资料区域。

I want to add a menu item along side the [view] [edit] [files] ... menu links at the top of the user profile page. When a user clicks it, it should behave like the others, in that it doesn't just launch to a new page, but the menu item they clicked on (let's call it "Funky Button") turns greyish and the user remains in the user profile area.

我创建了一个如下所示的钩子:

I've created a hook like below:

function my_module_funky() {
    // TODO: what to do?
}


function my_module_menu() {

    $items['user/%user/funky'] = array(
        'title' => t('Funky Button'),
        'page callback' => 'my_module_funky',
        'page arguments' => array(1),
        'access callback' => TRUE,
        'access arguments' => array('access funky button'),
        'type' => MENU_LOCAL_TASK,
    );

    return $items;
}

所以上面的代码片段添加了按钮 -​​ 但是我不能如何让它显示像视图和编辑按钮显示他们的内容。谢谢!

So this above code snippet adds the button -- but I can't figure out how to get it to display like the view and edit buttons display their content. Thanks!

推荐答案

您的回调需要返回包含要显示的页面的HTML代码的字符串,例如:

Your callback needs to return the string containing the HTML code of the page to display, for example:

function my_module_funky($user){
 drupal_set_title('Funky page');
 return 'This is the $user value: <pre>'.var_export($user, true).'</pre>';
}






$ user 来自的页面参数'=>您的 rel = nofollow> hook_menu 实现,它将%用户通配符的值作为页面回调的第一个参数传递。


$user comes from the line 'page arguments' => array(1) of your hook_menu implementation which transmits the value of the %user wildcard as first argument of your page callback.

如果是复杂的页面,您可能需要使用模板文件创建一个主题功能,这样可以将页面的代码存储在.tpl.php文件中,这使得它更容易维护(特别是如果您的模块创建了许多这样的自定义页面)。

If it's a complex page, you may want to create a theme function with a template file, that way you can store the page's code in a .tpl.php file, which makes it easier to maintain (especially if your module creates many such custom pages).

这也有利于允许主题通过提供自定义页面输出他们自己的版本的.tpl.php文件,如果你的模块变得流行或其他模块可以预处理页面来添加/修改变量。

This would also have the benefit to allow themes to customize the page output by providing their own version of the .tpl.php file if your module becomes popular or other modules could preprocess the page to add/modify variables.

这篇关于Drupal用户配置文件页面中的自定义菜单选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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