drupal 以编程方式禁用或删除节点创建节点链接

发布于 2024-12-18 11:23:43 字数 130 浏览 2 评论 0原文

在有机群组的背景下,我正在编写一个模块,该模块将阻止不是群组成员的用户向该群组添加群组帖子。

我的模块当前设置必要的权限并检测用户是否具有该权限。

因此,当用户查看群组页面时,我想禁用/删除创建群组帖子的标准链接。

In the context of organic groups, I am writing a module which will stop users who are not members of a group from adding group posts into that group.

My module currently sets the permissions necessary and detects whether a user has the permission.

So when a user(s) are looking at a group page, I want to disable/remove the standard link to create group posts.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

辞别 2024-12-25 11:23:43

试试这个方法。

function mymodule_menu_alter(&$items) {
    global $user;
    // Perform code for finding out users permissions.
    // lets suppose we set true or false to $restricted after all
    if ($restricted && isset($items['node/add/yourtype'])) {
        $items['node/add/yourtype']['access arguments'] = FALSE;
        // or unset($items['node/add/yourtype']) to remove item for user
    }
}

Try this method.

function mymodule_menu_alter(&$items) {
    global $user;
    // Perform code for finding out users permissions.
    // lets suppose we set true or false to $restricted after all
    if ($restricted && isset($items['node/add/yourtype'])) {
        $items['node/add/yourtype']['access arguments'] = FALSE;
        // or unset($items['node/add/yourtype']) to remove item for user
    }
}
守望孤独 2024-12-25 11:23:43

如果我理解正确的话,您不希望某些用户创建内容类型。

所以步骤是:

1)创建一个菜单钩子。

// Here we make sure if the user goes to for creating this node type
// we can use the appropriate call back function to stop it.

function yourmodoule_menu() {
    $items = array();
    $items['node/add/page'] = array(
        'page arguments' => array('yourmodule_additional_actions'),
        'access arguments' => array('administer create content')
    );
}

2)然后制作一个权限钩子以确保只有某些用户拥有此权限。

// drupal will only allow access to to path 'node/add/page' with people
// who have access given by you.

function yourmodule_permission() {
    return array(
        'add content' => array(
            'title' => t('Administer create conent'),
            'description' => t('Perform administration tasks and create content')
         )
    )
}

3) 为那些有权限的用户编写代码。

// Only affter they have this permisson drupal will allow them access
// to the below function.

function yourmodule_additional_actions() {
    // this code will  only execute if the user has the permission
    // "Administer create conent"
}

If I understood right you don't want certain users to create a content type.

So the steps are:

1) Create a menu hook.

// Here we make sure if the user goes to for creating this node type
// we can use the appropriate call back function to stop it.

function yourmodoule_menu() {
    $items = array();
    $items['node/add/page'] = array(
        'page arguments' => array('yourmodule_additional_actions'),
        'access arguments' => array('administer create content')
    );
}

2) Then make a permission hook to make sure only certain users have this permission.

// drupal will only allow access to to path 'node/add/page' with people
// who have access given by you.

function yourmodule_permission() {
    return array(
        'add content' => array(
            'title' => t('Administer create conent'),
            'description' => t('Perform administration tasks and create content')
         )
    )
}

3) Write your code for those users who have the permission.

// Only affter they have this permisson drupal will allow them access
// to the below function.

function yourmodule_additional_actions() {
    // this code will  only execute if the user has the permission
    // "Administer create conent"
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文