I'm trying to bootstrap Drupal from an external script, and to pass a string containing page content to drupal_render_page(). The external script lives in a subfolder of my Drupal install dir.

All is going quite well, except that the page renderer is failing to output any CSS includes in the HTML head. After much hunting, I discovered that the cause was a file_exists() check in drupal_pre_render_styles() that's not prepending DRUPAL_ROOT to the file path.

Attached patch fixes this. After applying, CSS outputs normally, the $styles variable once again gets populated and outputted in html.tpl.php.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Status: Needs review » Needs work

The last submitted patch, pre_render_styles_drupalroot.patch, failed testing.

Jaza’s picture

Status: Needs work » Needs review
FileSize
838 bytes

hmmm... seems that stylesheet paths can also be passed in stream wrapper form (e.g. color modules passes them in 'public://' form). Prepending DRUPAL_ROOT to such paths doesn't work.

Updated patch attached - doesn't prepend DRUPAL_ROOT if the stylesheet path is in the form 'anystreampath://'. Otherwise unchanged.

marcingy’s picture

Status: Needs review » Needs work

You should use

$file_path = file_uri_scheme($item['data']) ? $item['data'] :  DRUPAL_ROOT . '/' . $item['data'];;

You might also want to call file_stream_wrapper_valid_scheme.

marcingy’s picture

Version: 7.x-dev » 8.x-dev

Also should be fixed in d8 first.

Jaza’s picture

Version: 8.x-dev » 7.x-dev
Status: Needs work » Needs review
FileSize
825 bytes

Actually, this bug is not applicable to D8, as this file_exists() check was removed in (see for explanation).

So, this is just a D7 bug - and in my opinion, it is a bug fix and not a new feature or a compatibility-breaker. So, should be committed as a D7 maintenance fix.

Attached patch uses file_uri_scheme() instead of a regex check (per @marcingy in #3), against latest D7.

Jaza’s picture

Sorry, lost some formatting in my last post. Meant to say:

Actually, this bug is not applicable to D8, as this file_exists() check was removed in http://drupalcode.org/project/drupal.git/commit/68395ee (see http://drupal.org/node/575298#comment-6774212 for explanation).

tim.plunkett’s picture

Priority: Major » Normal

The external script lives in a subfolder of my Drupal install dir.

That makes this not major. Still a bug though.

Jaza’s picture

Status: Needs review » Needs work

New meta-issue for wider discussion of this issue: #1928072: Bootstrapping Drupal from outside the Drupal root directory