开发者

Do pages get generated before nodes in Drupal 7?

As I move into Drupal 7, I'm suddenly very confused about something that I thought I understood (or didn't need to understand in the considerable amount of time I've spent in Drupals 5 and 6 --

I'll be working on a module and, in the process of developing the code, I'll throw in a few ca开发者_JAVA百科lls to dsm() and/or drupal_set_message(). In my previous work, these calls always worked the way I expected -- on the next page submission, the dsm's would run, produce whatever they produced, and the results would end up on the page. In Drupal 7, I'm doing the same thing, but am finding that they're showing up one page too late -- I have to refresh the page to see them. This makes me think that the Drupal 7 evaluation model is that the selected page template gets evaluated and then -- and only then -- does the node being displayed on the page get loaded and rendered. Sure enough, A few tests with watchdog() and sleep() confirm this -- the page template definitely starts to get processed before the node inside the page is processed. (This is with only-very-slightly changed versions of the standard D7 page template, and no funky tweakings of internal D7 behavior, btw, and I'm doing nothing special with caching -- all of the caching options on Config > Development > Performance are turned off.)

This explains the message behavior -- the page template puts up whatever messages it has available at the beginning of the page rendering process, and then works on the node. If any messages get generated while the node is getting rendered, they go on the message stack, but they won't appear on this version of the page since the message stack has already been rendered (and cleared) by the page template. But this seems like the wrong thing -- I want those messages to appear as part of the immediate rendering of the page. I'm also certain that D6 didn't behave this way -- dsm() messages would appear right away. This isn't just a debugging matter; it's also messing up some form validation code, where the validation error doesn't appear on the page produced by the form submission, for exactly this reason.

Or so I think, anyway. Am I crazy, or deluded, or something else? Was there a change in D7 that led to this seemingly new behavior, or am I just confused? Many thanks for whatever clarifications might be out there....


Where exactly are you adding your dsm() calls?

The status messages are themed in http://api.drupal.org/api/drupal/includes--theme.inc/function/template_process_page/7 (Was template_preprocess_page in D6)

All messages which are added after that step, those in page.tpl.php for example, are only displayed on the next page. No idea about D5 but this was exactly the same in D6.

And everything that happens during the menu callback processing should be executed before and show up on the same page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜