Numeric menu paths (e.g. /404, /403) don't work.
function foo_menu() {
$items = array();
$items['403'] = array(
'title' => 'Access denied',
'page callback' => 'error_pages__error_page_403',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
With the code example above, an entry goes into the menu_router table with the path 0 (instead of the path 403).
This is because the router-building functions menu_router_build and _menu_router_build build an array structure where the path is the menu-key, and use array-handling functions which do not preserve numeric keys (i.e. array_merge and array_multisort.
E.g. within menu_router_build:
foreach (module_implements('menu') as $module) {
$router_items = call_user_func($module . '_menu');
if (isset($router_items) && is_array($router_items)) {
foreach (array_keys($router_items) as $path) {
$router_items[$path]['module'] = $module;
}
$callbacks = array_merge($callbacks, $router_items);
}
This could be solved in menu_router_build:
- $callbacks = array_merge($callbacks, $router_items);
+ $callbacks = $callbacks + $router_items;
However, _menu_router_build uses array_multisort in a few places, which would require more thought (perhaps writing a drupal-specific version of array_multisort, which preserves numeric keys?)
Comments
Comment #1
alexweber CreditAttribution: alexweber commentedConfirmed. There is also nothing in the hook_menu() documentation to suggest that numeric paths are not allowed, therefore there is nothing wrong with the path "403" and it should work as expected.
Comment #2
catchThis is at best an oversight, not a bug.
Comment #3
sunComment #4
manarth CreditAttribution: manarth commentedI disagree, it's clearly a bug. There's no mention in the docs or code to say that paths must not be numeric; maybe this hasn't worked previously, but that doesn't imply that numeric paths is a new feature.
However, I shall hold off further comment until I've got a patch!
Comment #5
sunAFAIK, this is not supported as it implies a quite heavy slowdown in performance. I'm pretty sure there are existing issues on d.o containing the detailed history.
Comment #6
jonathan_hunt CreditAttribution: jonathan_hunt commentedI just ran into this issue building a new site in D7 that requires numeric paths. I'm working around this by prefixing my menu router entries and aliasing them (e.g. 78 -> aliased to somestring/78). It seems to me to be a bug that Drupal's menu building won't honour numeric paths but the alias handling will.
I've scanned the Drupal core issue queue and can't see any issues relating to this (searched using "numeric paths", though #512962: Optimize menu_router_build() / _menu_router_save() discusses menu building performance *in general*).
It would be good to check now whether the Drupal 8 routing system will handle numeric paths. It would be good if Drupal as a project committed to handling any valid path per RFC 2396 (http://www.rfc-editor.org/rfc/rfc2396.txt).
Comment #7
alexweber CreditAttribution: alexweber commented@sun regarding the performance hit, since the menu is almost always served from cache this shouldn't matter that much!
Comment #12
Anonymous (not verified) CreditAttribution: Anonymous commentedNow numeric path works perfect. After #2107533: Remove {menu_router} we have not
menu_router_build
and_menu_router_build
. May be to close this issue, or move back to d7?Looks like d7 already has issue about performance #512962: Optimize menu_router_build() / _menu_router_save() (if we want to move by #5).
Comment #13
Anonymous (not verified) CreditAttribution: Anonymous commentedComment #14
poker10 CreditAttribution: poker10 at ActivIT s.r.o. commentedThis should be a duplicate of #2456193: Menu links - not possible to create numeric paths. This issue already has patch and some progress.