Hi,
in my module I want to overwrite some menu entries made by the user.module. So I have given it a weight of 5 in the system table. Thus my_module_menu() is called after user_menu() and my module overwrites the entries of the user.module in _menu_build(). That's fine. But some menu entries are dynamic and added in _menu_append_contextual_items(). However, in that function existing menu entries are only overwritten if their type contains MENU_CREATED_BY_ADMIN. This leads in most cases to the following behavior: If we have a module a with weigth of 1 and a module b with a weight of 2 and both modules implement menu_hook($may_cache). Then the menu entries from module b prevail for cached menu entries ($may_cache = TRUE) and the menu entries from module a prevail for uncached menu entries. So how can I achieve that my module can overwrite all menu entries made by user.module?
Regarding the callbacks there is something strange going on in there.
if (isset($item['callback'])) {
$_menu['callbacks'][$item['path']] = array('callback' => $item['callback']);
if (isset($item['callback arguments'])) {
$_menu['callbacks'][$item['path']]['callback arguments'] = $item['callback arguments'];
unset($item['callback arguments']);
}
unset($item['callback']);
}
is executed in every case. So the $_menu['callbacks'] are updated even if the new entries are not set in $_menu['items'].
if ($_menu['items'][$mid]['type'] & MENU_CREATED_BY_ADMIN) {
$_menu['items'][$mid]['access'] = $item['access'];
if (isset($_menu['items'][$mid]['callback'])) {
$_menu['items'][$mid]['callback'] = $item['callback'];
}
if (isset($_menu['items'][$mid]['callback arguments'])) {
$_menu['items'][$mid]['callback arguments'] = $item['callback arguments'];
}
}
Why the $_menu['items'][$mid]['callback'] = $item['callback']; statement? $item['callback'] is always unset (see above).
Comments
Comment #1
hajo commentedI don't know if this behviour is by design or if it is a bug. If it is by design I will really appreciate if somenone can explain me the code (there are not many comments in there). Thanks.
Comment #2
hajo commentedIf you want to know why I need this please have a look at http://drupal.org/node/316052#comment-1101919
Comment #3
ainigma32 commentedGood question. Unfortunately I don't have an answer for you. You might have better luck on the developers mailing list or IRC. If you can get a hold of drumm I'm sure he could shed some more light on this.
Or were you able to get an answer elsewhere already?
- Arie
Comment #4
gpk commentedSubscribe. Related: http://drupal.org/node/265260#comment-1018785.
The specific case in this issue could probably be (messily) worked round by using 2 modules, one of them (with a different weight) purely to handle the menu entries that the other one can't for the reasons described.
Comment #5
ainigma32 commented@hajo: Did you find someone to explain the code to you?
- Arie
Comment #6
ainigma32 commentedLooks like hajo won't be posting any feedback so I'm setting this to fixed.
Feel free to reopen if you think that is wrong.
- Arie