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.

apaderno
  • 28,547
  • 16
  • 75
  • 90
sisko
  • 9,604
  • 20
  • 67
  • 139

2 Answers2

2

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
    }
}
Vlad Stratulat
  • 1,296
  • 1
  • 10
  • 24
  • This helped alot. Still working on it but I think it's the solution I've been looking for. THANKS! – sisko Nov 29 '11 at 17:45
0

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"
}
Vlad Stratulat
  • 1,296
  • 1
  • 10
  • 24
Vishal Khialani
  • 2,557
  • 6
  • 38
  • 49
  • Thanks for your very detailed suggestion - it's appreciated. But hook_menu will have an effect across all groups for the targeted users. What I need is a means to deal with the target users selectively by detecting if they are or are not members of the group they are currently visiting – sisko Nov 29 '11 at 13:15
  • I can't seem to find the module there are too many with that name. paste the link and let me look at their code . Maybe I can suggest an alternative – Vishal Khialani Nov 29 '11 at 13:29
  • Sorry, not being clear again. I am developing the module. I have not found the desired functionality in Organic groups or any addon module, so I developing one – sisko Nov 29 '11 at 13:36
  • I think its simple then. So when the node ( group page ) loads check to see if the user is part of that group if not return a error . U can use the node_load node_view hooks for this – Vishal Khialani Nov 29 '11 at 13:43