0
votes

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.

2

2 Answers

2
votes

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
    }
}
0
votes

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"
}