views:

33

answers:

2

I'm in the process of making some improvements to a live Drupal site that's using the Domain Access module to run a number of microsites. I'm trying to find a way of restricting the menus a user can post content to from the node edit screen. A user on one of the domains should only be able to post content to menus associated with that domain.

Is there a simple way of achieving this? I'm guessing there are some hooks I could use, but so far I have been unable to identify them. I'd prefer not to have to install further modules to achieve this and to be able to add some code to the current site to alter the forms. The site is struggling with the large number of modules we've had to install on it already.

+1  A: 

According to the readme for the module, you need to set some specific permissions in user management:

To enable this feature, you should grant the 'edit domain nodes' and (optionally) the 'delete domain nodes' permission to some roles. Then assign individual users accounts to specific domains to assign them as Domain Editors.

From my experience many moons ago with the module, you can check the global $user object and figure out what domains the user should have access to. You can then use a form alter to remove any options from the select box that you don't want them seeing. As always with Drupal though, it's better to let someone else write the code - so if the Domain module provides this functionality, use it!

cam8001
Thanks, but that doesn't work on the setup I'm dealing with. Unfortunately I'm working with somebody else's build and it wasn't correctly setup in the first place. I'm sure if I can obtain the current domain's menus then I can alter the form accordingly.
monkeyninja
Do you know how to use hook_form_alter and interact with the global $user object?
cam8001
A: 

Eventually found a way of fixing this for the particular project I have been working on: in module_form_alter I've added the following:-

global $_domain;
if (isset($_domain['domain_id'])) { // only display domain's primary links
  $menus[domain_conf_variable_get($_domain['domain_id']
    ,'menu_primary_links_source')] = $_domain['sitename'].' Primary links';
}
if ( isset($menus) ) {
  $options = menu_parent_options($menus, $form['menu']['#item']);
  $form['menu']['parent']['#options'] = $options;
}

This restricts the menu options to just the current domain's primary links menu which is just what we wanted.

Thanks to Fabian who pointed me in the right direction earlier.

monkeyninja