[support] hook_load() called several times from menu items

Marco Lechner - IMR lechner at webgis.de
Wed Jan 9 20:39:06 UTC 2013


Hi,

I have a may be weird behaviour in the menu items of my module. To bring
it down to simple code I foo-bar-ed it on  [1]

To describe it in a few words:
In my modules-ui I define some paths/routes like /foo, foo/list,
foo/add, foo/%bar/delete, foo/%bar/edit ...

foo/list and foo/add are used to show a list if bar-objects or to open a
form to add a new one using simple _form()-hooks.

when editing, deleting or cloning an existing bar object a callback
function is used to create the form who takes the bar-object as input -
provided by the %bar -> bar_load()-hook

As long as foo/%bar/... items are not defined in my menu()-hook
bar_load() is never called, but as soon as foo/%bar/... items are added
to menu(), bar_load() is called several times (as often as menu-items
with %bar exist) even when I request for foo/add or foo/list (which do
not use %bar in any way.

Is this the intented behaviour? Why and which element calls the %bar
bar_load()-hook even when my URl request does not fit the
path-definition (foo/list instead of foo/%bar/edit -> I have no foo/%bar
or foo/%bar/ defined)

May be I still do not understand Drupals architecture and Hook-system in
a right way?

Marco

[1] http://pastebin.com/w0waVgX4


More information about the support mailing list