1

I am trying to figure out why hook_menu implementation is not working anymore after upgrade from 7.4 to 7.10 for a custom module Menu links were working properly until update to latest version. after update all custom module links are deleted from table menu_links and menu_router.

ex. of one of the menu link:

$items = array(); 

$items['a/main'] = array(
'page callback' => 'main',
'description' => 'Main front page',
'access callback' => TRUE,
);

return $items;  

This code was working properly in 7.4 but not anymore. Have tried to do all cache clearing, menu_rebuild()... etc. nothing seems to work.

Even tried to copy sample code from hook_menu API page like function mymodule_menu() { $items['abc/def'] = array( 'page callback' => 'mymodule_abc_view', ); return $items; }

function mymodule_abc_view($ghi = 0, $jkl = '') {
// ...
}

and does not work as well.

So I am wondering if anything changed after 7.4 version or I am really missing obvious details?

Thank you for comments.

1 Answer 1

2

Try adding a 'title' to your return array.

I noticed that the D7 menu documentation lists 'Title' as required:

"title": Required. The untranslated title of the menu item.

Now there is a comment on the doc page that claims it is not required.

But That comment is from March 20, 2011.

Perhaps the title is now finally required in a more recent release.

Edit: Your code from comment:

/** * Implementation menu(). / */
function misite_menu() {
    $items = array(); 
    $items['a/main'] = array( 
             'title' => 'main',
             'page callback' => 'main', 
             'description' => t('Main front page'),
             'access callback' => TRUE, ); 
    return $items; 
} 

/* * Implementation hook_theme(). */ 
function misite_theme() { 
    return array( 'main' => array ( 
        'template' => 'main', 
        'variables' => array('title' => NULL), 
        ),
    ); 
}

function main() {
    $path = drupal_get_path('module', 'a'); 
    $title = t(''); 
    $build['mainelement'] = array( '#theme' => 'main', 
                                                '#title' => $title, ); 
    $output = drupal_render($build); 
    return $output; 
}

Several observations.
1) I think your inclusion of hook_theme could be causing needless grief. Try getting an example of hook_menu working independent of hook_theme.

2) I wouldn't use 'main' as a page callback name; it may not be conflicting with another function elsewhere but I don't think it is a good idea regardless.

Try this:

function misite_menu() {
    $items = array(); 
    $items['a/my_main'] = array( 
             'title' => 'my_main',
             'page callback' => 'my_main', 
             'description' => t('Main front page'),
             'access callback' => TRUE
            ); 
    return $items; 
} 

function my_main() { 
    $output = 'HERE I AM'; 
    print($output); 
}

Then navigate to a/my_main and see if you can see "HERE I AM". If you can then you know your hook menu is working and that your problem is in your hook_theme.

0

Your Answer

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

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