<?php
/*
The following code does not do what I need or expect it to do. This is the first module I have attempted.
The plumbing is correct , as it does work - sort of.
What I am trying to do is add a button to the menu that will take the user to a custom page constructed from their
username. (construction of that page is fine, that is not the issue)
The code below works, but only for the lone administrator user.
The button does not show up for any other users. This appears to be because each user's page is set up as private
so permissions do not pass?. But if I force the permission to TRUE the button shows up, but the path it tries to access is
always for the administrator user. There is nothing dynamic about this approach. Why doesn't it work???
So, how can I accompish this? Obviously I am missing something, either in syntax/parameters or in my understanding of how the
drupal environment works.
It seems like this general approach simply will not work at all.
*/
/* drupal 6.x module */
/**
* Implementation of hook_menu().
*/
function myfavorites_menu() {
global $user;
$items = array();
$items[$user->name] = array(
'title' => 'My Favorites',
'description' => 'Go to Your Favorites Page',
'page callback' => 'go_home', /* same result if I cut out the middle man and use drupal_goto here */
'page arguments' => $user->name,
'access callback' => 'allow_all', /* should be 'access_user' but changed so it shows up all the time (I think this could be simply TRUE
without the function invocation)
This is weird because it seems like it is being
executed , as it prohibits access/display of menu item
to user other than the administrator */
/* I am disturbed by the passing remark in the documentation
"This hook is called rarely - for example when modules are enabled."
However, It must work somehow, as Others seem to have reported doing
dynamic menus in a similar way with previous drupal versions.
If I purposefully put a bad line in the code I get an error on any access so
it seems like it is being executed on every page access , yet the
"target" link is unchanged ??? */
'access arguments' => array($user->name),
/* Doesnt help 'type' => MENU_CALLBACK|MENU_NORMAL_ITEM, */
);
return $items;
}
function go_home($path) {
drupal_goto($path);
}
function allow_all($name) { /* this is bogus to force permission to be granted in all cases */
return TRUE;
}
I'm at jbonsteel@gmail.com
Thanks .
Comments
D6 menu works differently
The D6 menu has the ability to create dynamic menu items, it just does it differently than previous versions of drupal.
Start reading here --> http://drupal.org/node/109131
This page deals specifically with what you need I think --> http://drupal.org/node/109153
OK so how does this translate to what I need
From the page you cited. I see.
"
"
It seems like this or something close is what I need to adapt. The doc refers to argument 1. Argument 1 of what function? I do not know if the code above is sort of pseudo code or actual code. Here is my last attempt at this.(below) It does not work at all. No errors but no menu button in any case. I've tried a whole bunch of other variations, but it does not make sense to me. I have been an assembly language programmer for over 20 years. But I am new to php and drupal. I guess I need help deciphering this documentation. It seems cryptic and obtuse to me. It is making some assumptions I am not in on yet.
( added so it shows up prettier )
What is the correct syntax here?
Thanks.
Jeff
Argument 1, 2, etc...
This is an easier way of grabbing drupal url arguments. Take for example this path:
node/5/edit. 5 would beargument 1. This will pass in the $node object for that path (since it's a node, you can do the same for users). It's still kind of confusing I guess. It's so you don't have to mess with
if (is_numeric(arg(1)))crap.Here's another example. If this was complete it'd pop a local task or tab on every node if you had 'some permission here' access:
In your example above that you tried: