0

I have a module where hook_menu() was already used to process ajax calls, like this:

function bizaudit_menu() {
  return [
    'bizaudit/ajax' => [
      'page callback'     => '_bizaudit_ajax_handle',
      'access arguments'  => ['access content'],
      'type'              => MENU_CALLBACK,
    ],
    'bizaudit/autoexec' => [
      'page callback'     => '_bizaudit_autoexec_handle',
      'access arguments'  => ['access content'],
      'type'              => MENU_CALLBACK,
    ],
  ];
}

That works pretty well from times, then I just added another item, now to handle some precise route, like this:

function bizaudit_menu() {
  return [
    'bizaudit/ajax' => [
      'page callback'     => '_bizaudit_ajax_handle',
      'access arguments'  => ['access content'],
      'type'              => MENU_CALLBACK,
    ],
    'bizaudit/autoexec' => [
      'page callback'     => '_bizaudit_autoexec_handle',
      'access arguments'  => ['access content'],
      'type'              => MENU_CALLBACK,
    ],
    'navigate' => [
      'page callback'     => '_bizaudit_navigate_handle',
      'access arguments'  => ['access content'],
      'type'              => MENU_CALLBACK,
    ],
  ];
}

But this route seems to be never recognized!
To be sure I changed the callback function like this:

function _bizaudit_navigate_handle() {
  $query_params = drupal_get_query_parameters();
  echo implode('<br>', print_r($query_params, true));
  exit;
}

Using this url 127.0.0.1/apim/navigate should cause the query params to be printed (here empty, but no matter), and nothing else to happen.
Instead I get the normal content of the involved page displayed!
(I didn't omit to clear the cache)

Maybe I'm missing someting obvious?

  • Did you clear your cache? New items will not be picked up until you do. – Jaypan Sep 12 '19 at 8:02
  • @Jaypan Sure I did, as already stated in my question! – cFreed Sep 12 '19 at 11:09
  • What do you mean by "Instead I get the normal content of the involved page displayed!" normally if you tried a path that didn't exist you'd get a 404 page. So do you have another page that already exists on the url /apim/navigate? If so that might be your problem. Or did you mean you are seeing the 404 page content – Leigh Sep 12 '19 at 12:09
  • @Leigh Yes, a page "/apim/navigate" exists : it's a simple normal page, then it now needs some special process when it has some query params. It's why I want to intercept it using hook_menu(), where I would do some stuff before redirecting to the normal url (without the special query params). Would it be that hook_menu() never works if the stated item is a real page? – cFreed Sep 12 '19 at 12:38
  • 1
    @Leigh Thanks a lot: now I understand. And I don't need more help: with your explanation I could work differently, simply choosing to use a totally unknow path. In the other hand, you could post a real response, so I would accept it. Thanks anew. – cFreed Sep 12 '19 at 13:01
0

I think I see your problem

hook_menu is for defining your own page paths in code. It's not for hooking into the processing of a page that already exists. So you've got a conflict where you have 2 pages with the same url and the latter (the node/view page or whatever is it with the same url) is taking precedence over your bizaudit_menu definition. So your code created path is never triggered as Drupal has found another route for your "apim/navigate" path

| improve this answer | |

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.