Currently, you can’t set the Error 403/404 page to a menu callback that is not cacheable (i.e. that is defined in !$may_cache). If you for example set that page to node/20, the menu item for that node does not exist because it is generated on-the-fly based on what arg() returns.
The patch overwrites the $_GET['q'] parameter arg() uses. (The original destination is already stored in $_GET[‘destination’]). Then, these dynamically generated contextual items are loaded by calling _menu_append_contextual_items().
| Comment | File | Size | Author |
|---|---|---|---|
| #13 | rollback.patch | 1.19 KB | chx |
| #3 | error_menu_rewriting_0.patch | 770 bytes | kkaefer |
| error_menu_rewriting.patch | 936 bytes | kkaefer |
Comments
Comment #1
chx commentedComment #2
dries commentedcommin.inc shouldn't call private menu.inc functions...
Comment #3
kkaefer commentedRight. chx pointed me in the right direction. The fix is now general because it is in menu_set_active_handler().
Comment #4
chx commentedI looked around in core and found no problem with this. The only concern could be that now contextual items are added for the original and the changed path. However, when the tabs are rendered only the children of the active nontask item are taken into consideration so I fail to see how this could cause superflous tabs to appear.
Comment #5
chx commentedComment #6
dries commentedI don't understand this patch. menu_get_menu already calls _menu_append_contextual_items() ...
Comment #7
dries commentedCommitted to CVS HEAD. Figured it out with the help of chx.
Comment #8
(not verified) commentedComment #9
heine commentedReopening because this commit results in hook_menu(FALSE) called multiple times on certain pages; for example on taxonomy/term.
This happens when a module calls menu_set_active_location for example, taxonomy on taxonomy/term/tid pages.
As many modules, including core modules, have code inside hook_menu(FALSE) that is believed to run only once, this is a problem.
Possible solutions
1. Roll this back, reopen http://drupal.org/node/88474
2. Surround all code that should be only run once with static $ran; if (!isset($ran)) { ...
3. Introduce a hook_start
4. An additional parameter to hook_menu (see below) that allows code to distinguish between first and subsequent runs.
5. ?
I'm against 4, because such a modification could be done much cleaner with the introduction of hook_start. IMO, using hook_menu for this has grown organically.
Rolling this back, will affect the validity of hook_menu(false) results when ?q= changes on a menu_set_location change.
Note: http://drupal.org/node/88474 is dependend on this issue.
Here's the discussion from IRC (quoted with chx permission):
Comment #10
hass commentedhook_start sound good idea... however please check out node.module it uses a CSS to be added once and this one is only added once for sure...
Comment #11
heine commented@hass, that is due to the properties of drupal_add_css as node_menu is also run twice with $maycache = FALSE.
Comment #12
chx commentedNote that in http://drupal.org/node/88474 we can use drupal_goto (external redirect) instead of the menu_set_active_item (internal redirect) and that patch was submitted in there as #6 and reviewed in #9 and even RTBC'd just it was said to be ugly. Ugly it may be but solution it is. If you roll this back and I will submit one on 88474 to this effect. This is the least code to be changed, also. It will be a regression because then the original bug here 403/404 pages can only be cached pages but ah well. You can code around it by adding node/403 in a hook_menu to $may_cache part. Drupal 6 will have absolutely no problem with this.
Comment #13
chx commentedComment #14
dries commentedRollbacked. Thanks.
Comment #15
(not verified) commentedComment #16
jimmygoon commentedAfter recently setting up a new installation of Drupal 5.0 Gold I've encountered this problem:
I create two pages. One with a URL ALIAS of "lost-404", the other "lost-403". NEITHER HAVE MENU LINKS.
Now when I set those to be my error pages (Administration > Site Configuration > error pages)
If I visit http://www.example.com/drupal/this-page-doesnt-exist the /node/ page is shown. NOT THE CUSTOM PAGE.
Now if I go in, create menu links to both the "lost-404" and "lost-403" page, and delete them... the custom pages are used.
Thus I believe that this bug should still be open.
Comment #17
jimmygoon commentedWell, after more discussion in #drupal-support and more testing I believe I've narrowed it down to being an issue with aliased pages. I determined that by making another UNMENU'D page and setting it as my error page, this time using "node/4" rather than an alias (I didn't even give the page an alias). It worked.
So it works to use the node-path but not if you use an alias without a menu item. Hope this helps.
Comment #18
jimmygoon commented** closed again in favor of a new bug report: http://drupal.org/node/109748 **