0

I'm sure this is an obvious answer but I seem to be missing something important.

How can I add a link to a menu using hook_menu() to an already defined path?

I'm trying to add a direct link to a node/add page that already exists.

I need to use hook_menu() instead of the control panel.

2

You can best use hook_menu_alter(), which should be used when "Additional items may be added, or existing items altered."

In custom_node_add.module :

function custom_node_add_menu_alter(&$items) {
  if (aray_key_exists) { //some sanity checking;
    $items['node/add']['page callback'] = 'custom_node_add_page'
  }
}

function custom_node_add_page() {
  return t("Hello World! This is content on my node/add page");
}
0

I really should have spent more time searching. The following works beautifully in hook_menu();

$items['customeurltocreate/nodetype'] = array(
        'title' => 'Create Node Type',
        'page callback' => '_menu_create_node_type',
        'type' => MENU_NORMAL_ITEM,
    );

function _menu_create_node_type() {
    module_load_include('inc', 'node', 'node.pages');
    return node_add('node_type');
}
  • 2
    This only works if your module is called after that other module; which is very flakey. You should either force your module to be ran after that other by changing the weight in the system table. Or use hook_menu_alter – berkes Sep 2 '11 at 12:47

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.