My post on developing a custom search at http://drupal.org/node/124963 has helped one other person besides myself, so I am going to continue the technique here with a different problem.
Bear in mind, I am new to this platform and trying to learn it at a low-enough level that I can leverage it quickly in the future instead of always flailing around for a quick fix.
I need to get content from my node onto the users profile in a particular format/order.
I know that the user.module does it when the user clicks goes to view their own profile, so I start by hunting in there for clues.
Here is the user_menu stripped down to semi-pseudo code.
if ($may_cache) {
}
else {
if (WE HAVE A VALID USER ID) {
if ($user !== FALSE) {
$items[] = array('path' => 'user/'. arg(1), 'title' => t('user'),
'type' => MENU_CALLBACK, 'callback' => 'user_view',
'callback arguments' => array(arg(1)), 'access' => $view_access);
$items[] = array('path' => 'user/'. arg(1) .'/view', 'title' => t('View Profile'),
'access' => $view_access, 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10);
//edit user
//delete user
}
}
}
}
What jumps out here is that only the 'user/.arg(1) url invokes a callback, but testing both 'path' => 'user/'. arg(1) and user/'. arg(1) .'/view' on my site gave me the same view.
So, lesson there is that there *may* be something special about MENU_DEFAULT_LOCAL_TASK that automagically invokes hook_view...I don't know, but it is something to file away
Ok, back to my task...I know that the callback->user_view is where I probably need to be, so lets look at that next.
Comments
looking at user_view for clues on hacking into it.
Here is the user.module user_view hook.
the guts seems to be in the
loop, so lets grok that next.
grokking foreach (module_list() as $module)
ok, lets build from the ground up.
In my custom module, I define a menu callback for learning/debugging...
with callback to my debugging function ld_hack where I incrementally grok this bear.
I pull up the ld/hack url on my site and get the following...
i.e. a list of modules.
First question that comes up is this all modules in the modules directory? or only installed modules.
A quick check yields: ONLY INSTALLED MODULES. hooray, ok on to the next part...
grokking module_invoke()
Here is ld_hack with the original user_view code commented out as a reference below my working hacks
Since we know that we have a list of installed modules, it seems that user_view invokes hook_something_or_other on all installed modules.
First off, reading the docs on module_invoke ()shows a very different structure than what I see here.
http://api.drupal.org/api/HEAD/function/module_invoke
I don't know what's going on here, but lets continue and see what we can get.
here is ld_hack for next step.
running it, I get:
okey dokey loooks like the user module invokes its own hook...
none of the other modules were invoked.
the next question, is what hook?
hmmm.
which hook.
lets do something stupid.
we know the user module invokes a hook on itself (There is a lesson there!--a module can invoke a hook on itself)
lets modify the ld/hack to get some idea of what is going on..
with output
which seems to be saying to invoke the user_user hook in the user module.
lets see if there is a user_user hook there.
hmm.
whell there is!
here is the first few lines
so I need to implement a user hook taking args...
which returns and array
lets see what I can do.
gotta pick this up later
Boss wants me on another task for a bit, will pick this up asap.
t.
implementing the ld_user hook on ld.module
ok
We know that the ld_user('view') hook will be invoked from ld_hack (and from user_user as well)
so lets implement it.
Here is a stripped down version of the ld_user$op) hook
Now, before I go to ld_hack to dereference the above, I know that the user_user hook is calling this as well, so I go to my view user url
to see what gives, and I see.
Now, one of the things that is worrying me is my lack of control over the layout...I don't think I will have much--if any--but I don't know that yet.
I also need to specify which of the presented items is the header and the detail, but I don't have view of the original form.
I will get that in the next post
clarification on above
My ld_user('view') hook evolved between posts above. Here is a clarification with some additional modifications to make things clear.
here is the ld_user('view") hook
and here is the output
So, we build an array of items each with its caption and its value and then encapsulate that array in another array with a Title for the subsection that will be disiplayed.
Ok, this is making sense.
So, ld_hack needs to :
1. build an array of items to be displayed
2. encase that array in another array with a title.
what I need to do next is identify exactly the structure of the items array....
okey dokey,
progress.
devining the structure of the array to be returned to user_user
my last post, I left off here...
so, lets do that.
to start, I grepped the modules directory to see what modules implement hook_user..
bash-3.00$ grep -i _user\(and I get the following list of modules.
So what I will do next is pull the form structure from each of these and merge them into a form ..note. this will NOT mean that I have ALL the possible items things for the array, but it should help out for now.
t.
breakdown part 1
here is stage one of my analysis.
only 2 modules (besides user) implement the 'view' case for hook_user.
Here is the breakdown by 'case' passed to the hook...
some observations.
next up is the structure of the returned array....
t.
structure of the returned array.
Okey Dokey,
I have found two cases.
The first case is the easy case, it is from the blog_user
so we return an array arrays of strings named Header Name??
comes the profile_user case.
I am not going to post the code from the profile.module here, as it will clutter up the post.
However the relevant functions are profile_user, profile_view_profile and profile_view_field.
The answer to this quest is contained in the profile_view_profile function and here is the gist of the matter...
Translating, what is returned will be an array similar/identical to the simple case array, but which should be more usefull for my needs in ld.module
basically, profile_user('view') will return something like this.
('Contact Information'=>
('title'=>'work phone','value'=>'727.123.4567','class'=>'profile_work_phone')()....)
So for my ld module, I will return
('LD HEADING HERE'=>
('title'=>'work phone','value'=>'727.123.4567','class'=>'profile_work_phone')()....)
etc.
and that answers my question.
hope it helps.
t.