Hide the menu of other domains from node to change the form on the Drupal website using domain access

I am making some improvements on the real Drupal site using the Domain Access module to run multiple microsites. I am trying to find a way to limit the menu that a user can place on a web page with node. A user in one of the domains should be able to post content to the menu associated with this domain.

Is there an easy way to achieve this? I guess there are some hooks that I could use, but so far I have not been able to identify them. I would prefer not to install additional modules for this, as well as add code to the current site to change forms. The site is struggling with a large number of modules that we had to install on it already.

+1
source share
3 answers

I finally found a way to fix this for the specific project I was working on: in module_form_alter I added the following: -

global $_domain; if (isset($_domain['domain_id'])) { // only display domain 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 limits the menu options to only the main link menu of the current domain that we wanted.

Thanks to Fabian , who pointed me in the right direction before .

0
source

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

To enable this feature, you must provide "edit domain nodes" and (optionally) permission to "delete domain nodes" for some roles. Then assign individual user accounts in specific domains to designate them as domain editors.

From my experience many years ago with the module, you can check the global $ user object and find out which domains the user should have access to. Then you can use the form to remove any parameters from the selection field that you do not want to see. As usual, with Drupal, it's better to let someone else write the code - so if the domain module provides this feature, use it!

+1
source

Here is the 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 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; } } 
+1
source

Source: https://habr.com/ru/post/1312751/


All Articles