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

nevets’s picture

What defines 'foo/%node'?

Also 'hook_menu' is not the correct function name, you need to replace 'hook' with your module name.

mcdoolz’s picture

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.

nevets’s picture

You need to use the actual path (and not the alias) when defining menu items.

mcdoolz’s picture

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.

nevets’s picture

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 '%')

mcdoolz’s picture

Do I still need to use load argument?

-
Be the occasion.

nevets’s picture

No, if you use %node, Drupal will handle loading the node for you.

mcdoolz’s picture

Well there it is.

Thanks mate!

-
Be the occasion.