Closed (fixed)
Project:
Drupal core
Component:
base system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
13 Nov 2004 at 18:03 UTC
Updated:
1 Jun 2005 at 13:58 UTC
Jump to comment: Most recent file
While fixing the image browse module for 4.5 I found that drupal_set_html_head cannot be called from everywhere. It (obviously) only works when called before the header is printed/generated by the theme. The image_browse module wats to set javascript in the header from the block hook (any other palce would mean iether using globals or double database calls.).
We should either document that this is the case, or otherwise change its behaviour. The attached pathc adds a line of documentation.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | common_inc_header_doc_0.patch | 492 bytes | Bèr Kessels |
| common_inc_header_doc.patch | 494 bytes | Bèr Kessels |
Comments
Comment #1
Uwe Hermann commentedComment #2
dries commentedIRC, this can be called as long the headers aren't sent. Saying it must be called from _menu() or _init() doesn't sound right to me.
Comment #3
Bèr Kessels commentedTis small pathc conatins your exact words "This can be called as long the headers aren't sent."
Comment #4
Bèr Kessels commentedwhoops.
Comment #5
dries commentedCommitted to HEAD. Thanks.
Comment #6
Bèr Kessels commentedFor now I am bringing this back to life. (setting it to active).
I beleive documenting a "bug" is certainly not similar to fixing it. We should really find a way to "fix" this issue. But I cannot yet think of a way.
It is technically impossible to add something to the head when its arlready printed. So we need another solution. I am thinking of some flag that you can set (e.g. in init) called "wait_with_print" that, if set TRUE will hold "theme_page" untill all functions are ran, and the _exit() hoos is going to be called. Just before calling that hook, we can print the theme_page.
I am not too sure about all this. But I /am/ sure that it makes nearly no sense to have a drupal_set_html_head, if you can hardly use it.
please mark this closed or wontfix if there are valid reasons for not thinking about a better solution.
Comment #7
(not verified) commentedFirst, we should discourage use of init hook since it defeats many of the benefits of the bootstrap. Please don't mention it here.
Second, Dries is right that this function call can appear anywhere. The reason to put it in hook_menu(!$may_cache) is to guarantee that it gets called exactly once per page (no matter which module is rendering the page). This is the desired behavior when injecting CSS and Javascript and so on.
Comment #8
Bèr Kessels commentedfixed with the new methot of centralised theme_page print
Comment #9
(not verified) commented