I have a hook menu
$items['node/%/delete'] = array(
'title' => 'Delete',
'load arguments' => array(3),
'description' => 'Confirm the action.',
'page callback' => 'drupal_get_form',
'page arguments' => array('_mymodule_delete', 1),
'type' => MENU_CALLBACK,
'weight' => -4,
);
return $items;
What do I need to do to make sure the following function gets to work (and the variables get their values):
function _mymodule_delete ($form, $form_state, $node) {
...
}
In orther words, how do I get values in the three arguments given ($form, $form_state and $node)
EDIT
I’ll have another go…
The only argument(s) you need to pass to
drupal_get_form, other than the name of the form itself, are arguments specific to that form function;$formand$form_stateare automatically added for you. So if you want to call a form with a signature of_mymodule_delete($form, $form_state, $node)you would use this code:When you apply this to the menu router, all you’re looking to do is pass the loaded
$nodethrough as an argument todrupal_get_formin the same way. Your router item would look like this:Your original example is missing the
access arguments/access callbackattribute which would make your page inaccessible (403 status) so I’ve added in the ‘standard’ access arguments ofaccess content. You’ll probably want to change this for your own needs.The string
node/%node/delete(the router path) and the page arguments array are the bits you’re probably interested in here. When you want to pass an argument from the URL to a callback function you simply include it’s ‘index’ as one of the page arguments. This index comes from a zero-based array of the router path when split by the separator (/).In this example the three parts of the path are:
As the variable element of the path is in index position
1, that’s the number we pass to thepage argumentsarray.Just to make it a little more complicated, the variable passed in through the path can also be passed to a load function before it’s passed to the
page callbackfunction. For some reason the naming convention in Drupal is that a function with the name of the variable with_loadappended to it will be the name of the function called.So in this case,
node_loadis called. If your router path was, for example,books/%bookthen a function calledbook_loadwould be called to prepare the variable to be passed to thepage callbackfunction.The load function is optional, if your path was
node/%/deletethen the argument passed to your form callback would be the exact string (in this case a node ID) from the URL.I’m sure you’ve seen it but the
hook_menu()documentation tries its best to explain all this, I can understand why it would be difficult to comprehend though.Hope that helps.