Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By mcdoolz on
function awesome_callback($node){
drupal_goto('node/add/foo?destination='.$node->path);
}
function hook_menu() {
$items['foo/%node/new'] = array(
'title' => 'Create a new foo',
'description' => 'Click to create a new foo',
'page callback' => 'awesome_callback',
'access callback' => TRUE,
'type' => MENU_LOCAL_ACTION,
'page arguments' => array(1),
'load arguments' => array(1),
);
return $items;
}
I clear cache and go to url.com/foo/anode and there's no action link. I've been tinkering with it for an hour and from what I can see, this is how it's done. Help?
Comments
What defines 'foo/%node'?
What defines 'foo/%node'?
Also 'hook_menu' is not the correct function name, you need to replace 'hook' with your module name.
I used hook for the sake of
I used hook for the sake of example; I should have clarified.
foo/%node is the url alias to a node in this case, hence why I've written foo as opposed to node. Suppose I should have clarified that as well.
-
Be the occasion.
You need to use the actual
You need to use the actual path (and not the alias) when defining menu items.
success
Thanks for the responses, Nevet!
Using node/%/new as the registered path works so:
$items['node/%/new'] = array(etc.)
Does %node not define the type of entity (node)?
If I use 'load arguments' on the first argument (node) it should load the node, but I had to node load in my callback to get at the node information; is that normal?
-
Be the occasion.
Instead of $items['node/%/new
Instead of
$items['node/%/new']
you want to use$items['node/%node/new']
. Using %node instead of '%' will cause the node to be passed to the callback (instead of the nid you get when using '%')Do I still need to use load
Do I still need to use load argument?
-
Be the occasion.
No, if you use %node, Drupal
No, if you use %node, Drupal will handle loading the node for you.
Well there it is.
Well there it is.
Thanks mate!
-
Be the occasion.