views:

47

answers:

1

I wanted to add a tab to the user edit page ie user/%/edit/foo, and was using the twitter module as a model. After much spelunking and stepping through with a debugger, I realised that I needed to add a hook_user function in my module so that the %user_category part of the menu router path would work.

It's now functioning as expected, but I don't really have a solid idea of what I just did, and haven't found a good explanation anywhere.

Can anyone explain to me what it's about?

A: 

When you use %user_category it means that user_category_load function is called with that argument (the uid).

The function is defined in the user module. These functions serve as a validation, if False it return FALSE, it will result in a 404, but if it return something else, like a user object, that will be passed to whatever callback function / form is run for that url.

In your case, you could probably have used %user instead which would have called user_load which is more simple, and you wouldn't have needed to do all the extra stuff to make user_category_load pass.

Summary

So user_category_load does two things.

  1. Check that the category exist so you just can't do user/%/edit/foo.
  2. Caches the user object.
googletorp
Can you explain the problem that user_category_load solves? When _can't_ I just use %user?
Andrew
I guess I still don't quite see _why_ it does #1. Or, for that matter, what as user_category is.If I set up a menu item at something like `user/%/edit/foo`, why would I want/need to go through this extra hoop? What does it do that user_load by itself doesn't do?
Andrew

related questions