In hook_menu() there are ten entries, but some of them are shortcuts to the same place, and this is achieved using a page callback which just calls drupal_goto. This initially obscured the actual url of the menu item. For clarity, if an item has a page callback which only does a drupal_goto() I think the menu item should do the drupal_goto directly. It is then clearer when reading the hook_menu function what exactly each link does and what the final url will be.
For example:
// Tab for Admins to have quick access back to main weblinks page.
$items['admin/config/content/weblinks/links'] = array(
'title' => 'Links page',
'page callback' => '_weblinks_settings',
'access arguments' => array('access web links'),
'type' => MENU_LOCAL_TASK,
'weight' => 10,
);
can be replaced with
// Tab for Admins to have quick access back to main weblinks page.
$items['admin/config/content/weblinks/links'] = array(
'title' => 'Links page',
'page callback' => 'drupal_goto',
'page arguments' => array('weblinks'),
'access arguments' => array('access web links'),
'type' => MENU_LOCAL_TASK,
'weight' => 10,
);
and we can delete the function
function _weblinks_settings() {
drupal_goto('admin/config/content/weblinks');
}
Comments
Comment #1
jonathan1055 commentedPatch for all three of these.
Comment #2
gstegemann commentedPatch applied and committed.
Please note: after applying this patch the cache has to be cleared.
Comment #3
gstegemann commentedComment #4
jonathan1055 commentedThanks Gerhard. I presume you were happy with my explanation of why I think it is clearer to have the drupal_goto and final url within the hook_menu()
If you use the devel module, they have a nice 'rebuild_menus' link which calls the necessary menu_rebuild()
Comment #5
gstegemann commentedYes, sure. But the implementation of hook_menu was basically taken from the D6 version. I really didn't spent much time analyzing the code in more detail and for any further optimizations.
Thanks for your hint regarding the 'rebuild_menus' link. But on sites w/o the devel module clearing the cache works as well.
Comment #6
nancydruAnd the D6 version may have been rushed and never revisited.
I recommend the Admin_Menu module which also has cache clearing functions.
Comment #7
gstegemann commentedQuite possible.
In fact I have used the Admin module cache clearing function.