Search code examples
drupalmenudrupal-domain-access

Hide other domains' menus from node edit form on a Drupal site using domain access


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.


Solution

  • 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.