By somebodysysop on
Tried to find some documentation on this that includes examples I can use, but couldn't. If anyone has suggestions, please let me know.
According to http://drupal.org/node/103114, I assume that everything that went into D5 hook_menu $may_cache stays in hook_menu() (with new syntax). It also appears that everything that was !$may_cache goes into hook_init(). But, I don't see the syntax for that.
So, for example, in 5.x my hook_menu() is:
$items = array();
if ($may_cache) {
$items[] = array(
'path' => 'admin/og/og_user_roles',
'title' => t('Organic groups user roles'),
'description' => t('Allows group administrators to add members into group roles.'),
'callback' => 'drupal_get_form',
'callback arguments' => 'og_user_roles_admin_settings',
'access' => user_access('administer og_user_roles'),
'type' => MENU_NORMAL_ITEM
);
}
else {
// modr8 modification
if (module_exists('modr8')) {
if (arg(0) == 'node' && is_numeric(arg(1))) {
$node = node_load(arg(1));
if (!empty($node) && $node->moderate) {
$items[] = array('path' => 'node/'. $node->nid .'/ogmodr8', 'title' => t('Moderate'),
'callback' => og_user_roles_modr8_page,
'callback arguments' => $node->nid,
'access' => user_access('moderate content'),
'weight' => 5,
'type' => MENU_LOCAL_TASK);
}
}
}
// Add another tab to the group subscribers page for admins to
// configure member roles
if (arg(0) == 'og' && arg(1) == 'users' && is_numeric(arg(2))) {
$gid = arg(2);
if (og_user_roles_is_allowed($gid)) {
$items[] = array(
'path' => "og/users/$gid/roles",
'title' => t('Configure member roles'),
'callback' => 'og_user_roles_page',
'callback arguments' => array($gid),
'access' => user_access('configure member roles'),
'weight' => 5,
'type' => MENU_LOCAL_TASK
);
}
}
}
return $items;
How do I code everything in the "else" clause in hook_init() (if that is what I'm supposed to do?)?
Thanks for any help anyone can provide.
Comments
The may_cache variable is
The may_cache variable is not used anymore for hook_menu. It looks like you are interested in wildcards:
http://drupal.org/node/109134
Also, here is an example on the API Site:
http://api.drupal.org/api/function/page_example_menu/6
-Craig Jackson
-Web Developer
Thank you! Looks like this is what I needed
It's slowly starting to make sense. This example actually helps. Guess I don't need hook_init after all!
Little Help?
I'm beginning to modify a module that can't yet be activated in D6 because the module it depends on (Organic Groups) doesn't yet have a version 6 release. I've read the new hook_menu documentation, but still come upon some things that I'm just not quite sure about.
Is this how I convert the following in hook_menu?:
To this?:
I thought about using 'oguseredit/%user', but user_load requires the argument array(uid=>number), and I don't see instructions for that here.
If the oguseredit/% is
If the oguseredit/% is editing your own account, you can use user_current after it. The user module does it like this:
That creates the 'My Account' menu item and it will link to the current user's profile. Plus %user_current also loads the current user object when passing the argument.
-Craig Jackson
-Web Developer
One more question regarding wildcards...
Since array(3) represents node_load(arg(3)), can I use the statement array(3)->nid for the node id. Or, for that matter, array(3)->type for the node type?
I would not think so,
I would not think so, because the array(#) is not an object (EDIT: Let me rephrase. When you pass the array. It does not know what the method nid is to the class array. I might be making it more confusing.). It is during the menu building process, that creates the object, and passes it as arguments to the callback function. Well, I have just passed the whole node, unless you are using a lot of memory, it shouldn't be that big of a difference for you. However, if memory is a problem and you only want the nid as a variable and not the node object. You could just use the page callback as a means of passing only the nid.
-Craig Jackson
-Web Developer
Yes, thanks for this.
Looks like I just needed to re-think what I was doing:
Thanks so much for the input!