4

In drupal you have the standard commands edit and delete which you access typing :

node/99/edit
node/99/delete

I want to create some other commands like :

node/99/approve
node/99/test
...

Where do I hook to access the command and execute some code ?

1 Answer 1

5

You need to use hook_menu() to define the path, coupled with the MENU_LOCAL_TASK type, e.g.

function MYMODULE_menu() {
  $items['node/%node/approve'] = array(
    'title' => 'Approve',
    'type' => MENU_LOCAL_TASK,
    'access arguments' => array('my custom args'),
    'page callback' => 'MYMODULE_approve_node_page',
    'page arguments' => array(1),
    'weight' => -1 // Controls the display order for the tab
  );

  return $items;
}

Then you just implement a callback function, which has the node passed as a parameter, and build up your page output:

function MYMODULE_approve_node_page($node) {
  // Do something with $node...
  $build = array(
    '#markup' => node_view($node, 'teaser')
  );

  return $build;
}

Once you clear Drupal's caches you should see the new tab appear alongside the View/Edit tabs on a node page, but only for those users who have the permission you define in your access arguments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.