Question

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.

Was it helpful?

Solution 3

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.

OTHER TIPS

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!

Here is some updated code for Drupal 7:

/**
 * Implements hook_form_FORM_ID_alter().
 */
function MYMODULE_form_page_node_form_alter(&$form, &$form_state) {
  global $_domain;
  if (isset($_domain['domain_id'])) { // only display domain's primary links
    $menus[domain_conf_variable_get($_domain['domain_id'], 'menu_main_links_source')] = $_domain['sitename'].' Main menu';
  }
  if (isset($menus)) {
    $options = menu_parent_options($menus, $form['#node']->type);
    $form['menu']['link']['parent']['#options'] = $options;
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top