from sun's issue here: #849862: Bartik code problems

+++ themes/bartik/bartik.info 6 Jul 2010 03:48:59 -0000
@@ -0,0 +1,39 @@
+stylesheets[all][] = css/maintenance-page.css

Why is the maintenance page stylesheet loaded on all regular pages?

Comments

bleen’s picture

Status: Active » Needs review
StatusFileSize
new1.27 KB
sun’s picture

Status: Needs review » Needs work
+++ themes/bartik/template.php	11 Jul 2010 11:19:37 -0000
@@ -144,3 +144,10 @@ function bartik_page_alter(&$page) {
\ No newline at end of file

This should not happen.

Also, when looking at the existing functions in the file, appending to the bottom does not really make sense to me.

Either before bartik_process_maintenance_page(), or right at the beginning before bartik_preprocess_html(). Trying to wrap my head around the current order, I guess the author intended the former.

43 critical left. Go review some!

bleen’s picture

Status: Needs work » Needs review
StatusFileSize
new1.42 KB

Why not just add the CSS in the existing maintenance_process function...

sun’s picture

Status: Needs review » Needs work

process is too late for adding CSS or JS. That must always be done in preprocess.

bleen’s picture

Status: Needs work » Needs review
StatusFileSize
new1.34 KB

Hmm ... ok. @sun - can you explain when to use hook_preprocess functions vs. hook_process functions. I've been asking in IRC all week and no one has had a good answer.

In any case... lets try this.

sun’s picture

Status: Needs review » Reviewed & tested by the community

Thanks, looks better.

Process functions have been introduced to account for the fact that multiple preprocess functions may add further CSS and JS to a page or do some other trickery. Problem space being that the implementing module or system functionality needs or wants to consume and (re-)compile all added or altered things prior to passing them of to the template. Such as $scripts or $styles variables in html.tpl.php.

http://api.drupal.org/api/search/7/template_process_ is the complete list of process functions. Looking at http://api.drupal.org/api/function/template_process_html/7, you can see how this default template process function collects and prepares a list of variables for the template. This means that drupal_add_js() and drupal_add_css() can still be used in *_preprocess_html() implementations. While it is true that we could have used THEME_process_page() here (since it is not THEME_process_html), the general rule of thumb is that preprocess is for adding + preparing stuff; only use process if you need to rely on and process stuff added via preprocess.

Perhaps we need to improve the documentation on this. Not sure where that is currently located though. (d.o handbooks, perhaps?)

dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.