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

hajo’s picture

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

hajo’s picture

If you want to know why I need this please have a look at http://drupal.org/node/316052#comment-1101919

ainigma32’s picture

Status: Active » Postponed (maintainer needs more info)

Good 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

gpk’s picture

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

ainigma32’s picture

@hajo: Did you find someone to explain the code to you?

- Arie

ainigma32’s picture

Status: Postponed (maintainer needs more info) » Fixed

Looks 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

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.