0

As the title suggests I'm getting intermittent errors when hook_menu is called. Based on the error message it's as if the callback can not be found. Clearing the cache resolves the issue and the page works as expected. However, if the server is idle the error reappears. Any ideas as to what might be happening? Here are some details:

Error as reported in log:

Warning: call_user_func_array() expects parameter 1 to be a valid callback, function '_protected_download' not found or invalid function name in menu_execute_active_handler() (line 517 of /var/www/drupal/includes/menu.inc).

All code is in the my_module.module and the module is enabled:

function my_module_menu()
{
    $items = array();
    $items['lesson-register-for-download'] = array(
        'path' => 'download/register',
        'title' => t('Register to Download a Lesson Plan'),
        'title callback' => FALSE,
        'access callback' => TRUE,
        'type' => MENU_CALLBACK,
        'page callback' => '_protected_download',
    );
    return $items;
}

function _protected_download()
{
    // check cookies and redirect here
}
1
  • As side note, the "path" property is not used anymore in Drupal 7.
    – apaderno
    Jul 18, 2013 at 4:39

2 Answers 2

1

You say your code is in my_module.inc, which means you have to tell the menu system that it is in there.

By default drupal will load my_module.module, but because the function is not in there it can't find the function.

As a side note, generally you should put hooks like hook_menu() in the .module file.

To tell the menu system that it has to load my_module.inc for your menu callback, do this:

$items['download/register'] = array(
  'title' => 'Register to Download a Lesson Plan',
  'access callback' => TRUE,
  'type' => MENU_CALLBACK,
  'page callback' => '_protected_download',
  'file' => 'my_module.inc',
);

Note the 'file' param.

Also, I made a couple of other changes:

  1. Removed t() from the title and removed the 'title callback', because by default title callback is t().
  2. Removed the 'path' param and changes the array key for the menu item. The path param was used in drupal 6 but not in drupal 7.
1
  • Thanks for the code clean up notes. I've implemented those pieces. Also, the module file being my_module.inc was a typo. I've edited the question to reflect that. For whatever reason I am not having this issue any longer and I'm not sure what fixed it. I guess a happy side effect of fixing a bug somewhere else?
    – David
    Aug 21, 2013 at 16:59
0

the callbacks are written to menu_router.page_callback; maybe find that record and then go look when the error occurs...

1
  • This is helpful. I didn't know that. I'll report back if after the error occurs this sheds some light on the issue.
    – David
    Apr 16, 2013 at 18:20

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