By mattrweaver on
I have run the og_files module through Coder to see if I can upgrade it to D6. I use the module on an intranet, and it also seems like the right size of module to use to learn about module development.
I got the database table to install, and the option to enable the module to appear in Organic Groups nodes, but the "Files" tab does not appear with those for the group.
Here is the D5 instance of hook_menu:
function og_files_menu($may_cache) {
global $user;
$items = array();
if(!$may_cache) {
if(arg(0) == 'node' && is_numeric(arg(1))) {
$node = node_load(arg(1));
if(isset($node->type) && $node->og_files_enabled && in_array($node->nid, array_keys($user->og_groups))) {
$items[] = array(
'path' => 'node/'.arg(1).'/files',
'title' => t('Files'),
'callback' => 'og_files',
'callback arguments' => array(arg(1)),
'type' => MENU_LOCAL_TASK,
);
}
}
}
return $items;
}
And this is what I have come up with as the D6 code:
function og_files_menu() {
global $user;
$node = menu_get_object();
if (isset($node->type) && $node->og_files_enabled && in_array($node->nid, array_keys($user->og_groups))) {
$items['node/'. arg(1) .'/files'] = array(
'title' => 'Files',
'page callback' => 'og_files',
'page arguments' => array(arg(1)),
'type' => MENU_LOCAL_TASK,
'access arguments' => array('OG Files'),
);
}
return $items;
}
I ditched $may_cache, and switched node_load to menu_get_object. But maybe I didn't get the array for $items[] right, or...well, if I knew, I wouldn't be posting, would I? :)
Can anyone give me a little help?
thanks
mrweaver
Comments
Try something like this
and
There might be other changes needed, but those were the ones that leapt out at me.
I tried it but...
nothing happened.
Is this line correct:
or do I need to include a variable?
Finished products are for decadent minds. -- Isaac Asimov
Try this: <?phpfunction
Try this:
Contact me to contract me for D7 -> D10/11 migrations.
I tried this...
but the tab still didn't appear.
Finished products are for decadent minds. -- Isaac Asimov
Cache Maybe?
If you make changes to the menu, you usually need to empty out the cache (or do some task that will empty the cache) before you can see the changes.
Exactly. Menu's are cached in
Exactly. Menu's are cached in Drupal 6, so no changes will be visible until the cache is cleared. On top of this, you will need to make sure that the user has 'OG Files' permission. Without this permission, the tab won't appear for anyone except user 1.
Contact me to contract me for D7 -> D10/11 migrations.
Forgot to mention...
I hadn't mentioned that I had cleared the cache tables after every code change. I'm doing this on a test site, running as user 1 and I'm still not seeing the tab.
I even tried creating a new group, just to see if starting with a fresh node might help, but no dice.
Also, I checked admin/user/permissions and OG Files doesn't appear there. So I'm wondering if I have another problem elsewhere in the module file.
Finished products are for decadent minds. -- Isaac Asimov
You don't see the permissions
You don't see the permissions in the permissions table because you haven't got hook_perm() in your module. You will also need to check all the conditions in this statement:
return (user_access('OG Files', $user) && isset($node->type) && $node->og_files_enabled && in_array($node->nid, array_keys($user->og_groups)));...to see what their values are. The basic outlay of hook_menu() with its callback function is ok in what you showed there, so something above is probably returning FALSE.
Contact me to contract me for D7 -> D10/11 migrations.
To test...
I'm reading up on Access Control. But, how can I structure the access callback just to make the tab appear for testing, to see if the module is working at all?
Does the
"page callback => 'og_files',refer to the function "og_files" in the module file?Finished products are for decadent minds. -- Isaac Asimov
If you want to test to see if
If you want to test to see if the tab is working at all, then change this code from my earlier post:
to this:
This means the access check will always return TRUE, so the tab will always appear.
Yes. The page callback is the name of the function that is called when the menu path is accessed. In your case, that's 'og_files'.
Contact me to contract me for D7 -> D10/11 migrations.
Aha!
Then there must be a bigger problem, because the tab still didn't appear.
I had tried changing access callback to "access callback => TRUE," and had no positive response (does this do the same thing as your most recent code?)
Could there be a problem with og_files_form_alter?
On the individual OG node page, the checkbox for enabling OG files appears checked as default when a node is created. Is it maybe not actually enabled?
Finished products are for decadent minds. -- Isaac Asimov
I had tried changing access
It's not the same thing. You aren't calling the acceess callback function in hook_menu(), you are just passing the name of the function that will be called. The actual calling of the function doesn't happen until later. So hook_menu() is expecting a string, which it will use later on by searching for a function with that name, and you are passing it a boolean. This isn't the same thing. That's why you need to return a value of TRUE from the function.
Contact me to contract me for D7 -> D10/11 migrations.