In the Drupal module, you can set hook_menu () and return $ items, in which the key is the url path. The question is - if several modules in hook_menu () have the same $ items key, for example, $ items ['user / manager'] - will all the 'page callback' functions work? I just recently found out that all modules are triggered if an event has occurred for which they are subscribed. Just like in java-script we sign a function for some event.

  • A debager is very necessary in Drupal, it will be difficult without it - Mykola Veriga

1 answer 1

In short, the answer is NO, only one page callback will work.

Look and see for yourself, I usually just start the debugger.

includes / menu.inc

/** * Collects and alters the menu definitions. */ function menu_router_build() { // We need to manually call each module so that we can know which module // a given item came from. $callbacks = array(); foreach (module_implements('menu') as $module) { $router_items = call_user_func($module . '_menu'); if (isset($router_items) && is_array($router_items)) { foreach (array_keys($router_items) as $path) { $router_items[$path]['module'] = $module; } $callbacks = array_merge($callbacks, $router_items); } } // Alter the menu as defined in modules, keys are like user/%user. drupal_alter('menu', $callbacks); list($menu, $masks) = _menu_router_build($callbacks); _menu_router_cache($menu); return array($menu, $masks); } 

This function returns a list of modules that use this hook.

 module_implements('menu') 

Further here in this $callbacks variable all $items will be seen. Since array_merge is used, you can look at an example of how it works and understand what will be obtained as a result.

 $items_1['path1'] = array( 'title' => 'title 1', 'type' => 2, 'description' => 'Text', 'page callback' => 'drupal_get_form', 'page arguments' => array('form_one'), 'access arguments' => TRUE, ); $items_2['path1'] = array( 'title' => 'title 2', 'type' => 2, 'description' => 'Text', 'page callback' => 'drupal_get_form', 'page arguments' => array('form_two'), 'access arguments' => TRUE, ); echo '<pre>'; print_r(array_merge($items_1, $items_2)); 

Conclusion:

 Array ( [path1] => Array ( [title] => title 2 [type] => 2 [description] => Text [page callback] => drupal_get_form [page arguments] => Array ( [0] => form_two ) [access arguments] => 1 ) ) 

As seen when declaring two identical paths, the second one will be used.