I have added pages using hook_menu like so:

function dynamic_entries_menu() {
    $items = array();
    $items['entries/get'] = array(
            'title' => 'Dynamic Entries',
            'page callback' => 'dynamic_entries_get_entry',
            'type' => MENU_CALLBACK
    return $items;

A node ID is added to the end of the URL. For example, /entries/get/10. I want to allow access to this page to anyone who has access to the requested node. How do I do that?


Use entries/get/%node as path and node_access() as access callback. Also, you might want to consider setting page arguments. It's not a good idea for the page callback to fetch the node id from the URL or using the arg() function.

$items['entries/get/%node'] = array(
  'title' => 'Dynamic Entries',
  'page callback' => 'dynamic_entries_get_entry',
  'page arguments' => array(2),
  'access callback' => 'node_access',
  'access arguments' => array('view', 2),
  'type' => MENU_CALLBACK,

BTW the function node_menu() is the hook_menu implementation of the node module. Looking up how the Drupal core modules implement certain hooks often helps.


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.