2

I am dealing with a custom search that, for years, has been accessible via /search. New site requirements call for the Search core module. However, that module has hardcoded /search in hook_menu().

I can not find a way to change the path for the core module without changing that module, which I do not want to do.

Notes:

  • I have seen hook_url_inbound_alter but I don't think this will work, as I still need /search to work.

  • I have disabled the menu item, but that just results in a "Not Authorized" page to non-admin users.

3
  • What do you mean by "maintaining the path"? It wasn't there when I answered and I don't know what you are trying to ask now.
    – Mołot
    Jul 9, 2013 at 14:52
  • @Mołot - sorry about that. I realized after posting the question, that it wasn't explicitly clear that I need to continue to use /search for the custom module. Jul 9, 2013 at 15:06
  • I edited your title to make it easier to understand. Hope you don't mind. If you do, of course edit again, just please keep it simple. And by the way my answer seems to meet your needs.
    – Mołot
    Jul 9, 2013 at 15:09

1 Answer 1

2

If you don't like what module sets in it's hook_menu(), alter it with your own hook_menu_alter(). Example code:

mymodule_menu_alter(&$items) {
  // Copy search to another place
  $items['look'] = $items['search'];

  // remove all old search settings
  // optional if you will also follow next step
  unset($items['search']);

  // add your menu item below instead of usual hook_menu
  $items['search'] = array(
    // ...
  );
}

This will unset /search path, and move all it's settings to /look path.

Worth noting is that if module generates links to /search anyway, it means it has it hardcoded somewhere. Happens. If so, you need hook_form_alter() or it's analogue to alter also these links.

1
  • Perfect! I failed to think about using hook_menu_alter() to actually add the item, thanks much! And your title edits make the question more clear than what I had. Jul 9, 2013 at 15:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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