简体   繁体   English

在Drupal中向用户添加新选项卡

[英]Adding a new tab to user in Drupal

How can I add a new tab to user profile. 如何向用户配置文件添加新选项卡。 I want to add for instance New User Tab which will be visible by administrator and user itself (not others). 我想添加例如新用户选项卡,管理员和用户本身(而不是其他人)可以看到它。

If you want to create your own module, the code will look like this: 如果要创建自己的模块,代码将如下所示:

<?php
// Define callback for tab.
function user_tab_menu(){
    return array(
        'user/%/new_tab' => array(
            'title' => 'New tab',
            'page callback' => 'user_tab_page',
            'page arguments' => array(1),
            'access callback' => 'user_tab_access',
            'access arguments' => array(1),
            'type' => MENU_LOCAL_TASK,
        ),
    );
}

// Show the page
function user_tab_page($uid){
    return 'New tab';
}

// Check if user has permission, or views its own page
function user_tab_access($uid){
    return ($uid == $GLOBALS['user']->uid) || user_access('view user tabs');
}

// Define permission for administrators
function user_tab_perm(){
    return array(
        'view user tabs' => array(
            'title' => t('View user tabs'), 
            'description' => t('View user tabs'),
        ),
    );
}

You can achieve this through the views module without having to do custom coding. 您可以通过视图模块实现此目的,而无需进行自定义编码。

Set up a new view page with path as 'user/%' Set contextual filter as 'user:uid' 设置一个新视图页面,其路径为'user /%'将上下文过滤器设置为'user:uid'

Set your page content as 'user' or 'fields' or whatever you want rendered. 将您的页面内容设置为“用户”或“字段”或您想要呈现的任何内容。 This is going to 'hijack' the standard drupal page into a views rendering. 这将把标准drupal页面'劫持'到视图渲染中。

Now you can add any amount of additional tabs by adding views pages and setting the path to 'user/%/path_of_your_tab'. 现在,您可以通过添加视图页面并将路径设置为“user /%/ path_of_your_tab”来添加任意数量的其他选项卡。 Set the menu entry for each tab to 'menu tab' and 'user menu' 将每个标签的菜单条目设置为“菜单标签”和“用户菜单”

You can then set access permissions in views for each tab. 然后,您可以在每个选项卡的视图中设置访问权限。

嗨朋友们,感谢您帮助我....我完成了代码

function downloaded_menu(){ $items['user/%user/downloaded'] = array( 'title' => 'Downloaded', 'page callback' => 'downloaded_content_page', 'access arguments' => array('access content'), 'type' => MENU_LOCAL_TASK, 'weight' => 10, ); return $items; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM