In 'mymodule', i try to override a menu url with hook_menu_alter, like this :

global $base_url;

$items['node/%node/delete'] = array(
  'page arguments' => array('myfunction', 1),
  'file' => $base_url .'/'. drupal_get_path('module', 'mymodule') .'/includes/custom_node_delete_confirm.inc',

I have an error because the file path is relative and begins with a "/"

Failed opening required

and this doesn't work too:

'file' => 'includes/custom_node_delete_confirm.inc'

How can i do this ? Thank You


You can set the file path explicitly:

file path: The path to the directory containing the file specified in "file". This defaults to the path to the module implementing the hook.

So your code might look like:

$items['node/%node/delete']['page arguments'] = array('myfunction', 1);
$items['node/%node/delete']['file'] = 'includes/custom_node_delete_confirm.inc';
$items['node/%node/delete']['file path'] = drupal_get_path('module', 'mymodule');

Be careful not to completely overwrite an existing router item unless you absolutely need to, in your example you're removing the required access callback/access arguments, and also the title; instead only change the values you need to as in the example above.

  • 1
    It works, and you are right, i just need to override "page arguments" and "file". Thank you – pico34 Mar 21 '13 at 13:20

Try out this

'file' => drupal_get_path('module', 'mymodule') . '/includes/custom_node_delete_confirm.inc',
  • 1
    doesn't work :Failed opening required 'modules/node/sites/all/modules/mymodule/includes/custom_node_delete_confirm.inc – pico34 Mar 21 '13 at 13:16
  • because the module implementing the hook is the node module – pico34 Mar 21 '13 at 13:32
  • This does not work because the file attribute already uses the full path to the original module location, like that: Warning: require_once(/var/www/drupal/sites/all/modules/old_module/sites/all/modules/new_module/new_module.pages.inc): failed to open stream: No such file or directory. – Afr Jun 26 '14 at 7:51

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.