Would there be a way to ensure the css injector css files are loaded last by Drupal? Otherwise, it's hard to use it to effectively override certain module styles.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pebosi’s picture

i've got the same problem. but changing module to theme works for me:

drupal_add_css(file_create_path($css_rule['file_path']), 'module', $css_rule['media'], $css_rule['preprocess']);

to

drupal_add_css(file_create_path($css_rule['file_path']), 'theme', $css_rule['media'], $css_rule['preprocess']);

regards

philbar’s picture

Yep, here is my css:

<link type="text/css" rel="stylesheet" media="all" href="/modules/node/node.css?O" />
<link type="text/css" rel="stylesheet" media="all" href="/modules/system/defaults.css?O" />

<link type="text/css" rel="stylesheet" media="all" href="/modules/system/system.css?O" />
<link type="text/css" rel="stylesheet" media="all" href="/modules/system/system-menus.css?O" />
<link type="text/css" rel="stylesheet" media="all" href="/modules/user/user.css?O" />
<link type="text/css" rel="stylesheet" media="all" href="/sites/all/modules/cck/theme/content-module.css?O" />
<link type="text/css" rel="stylesheet" media="all" href="/sites/default/files/css_injector_1.css?O" />
<link type="text/css" rel="stylesheet" media="all" href="/sites/all/modules/tagadelic/tagadelic.css?O" />
<link type="text/css" rel="stylesheet" media="all" href="/sites/all/modules/faceted_search/faceted_search_ui.css?O" />
<link type="text/css" rel="stylesheet" media="all" href="/sites/default/files/color/garland-29b97441/style.css?O" />

I can't even override garland's color css.

pebosi’s picture

try setting the css injector rule to only "screen"

regards

Robin van Emden’s picture

Same problem, tried #3 suggestion, still injection before other css.

Robin van Emden’s picture

Version: 6.x-1.3 » 6.x-1.4
chrisschaub’s picture

Wouldn't suggestion #1 be a good fix to commit? Seems very sound, and if the module weight is set high as well then it should be last in the theme layer too?

lee20’s picture

+1 for #1!

-1 for #3

It's really a pain to try to override module css.

ryumkin’s picture

#1 + #3 = works

escoles’s picture

Setting to 'screen' only (#3) seems to work on my install. But wouldn't that still be a bug?

CORRECTION: #3 does NOT work unless you select "Pre-process HTML" on the rule edit screen. (If you don't select "pre-process", the rule actually comes FIRST.)

leon85321’s picture

confirmed #9 is right, will need to set to 'screen' only and the 'preprocess' needs to be checked!
Now it is loaded last so themes css are overridden.

Thanks!

lefnire’s picture

+1, please fix ala #1. One can only fool the theme so many times with !important and class/id-specific selectors.

mpotosnak’s picture

#1 also fixed issues fixed issues between wysiwyg and css injector. By selecting use theme css, the css injector code is now included.

Yay!

klonos’s picture

Title: CSS Injector css not loaded last » CSS Injector css not loaded last - Behave as theme CSS rule
Category: support » feature

I take it that #1 refers to line 37 in the css_injector.module file (6.x-1.4, 2010-Mar-08). Right?

If so, then people need to know that it changed a bit (more then a year has passed since #1). So, it needs to be changed from:

drupal_add_css(file_create_path(_css_injector_rule_path($css_rule['crid'])), 'module', $css_rule['media'], $css_rule['preprocess']);

to:

drupal_add_css(file_create_path(_css_injector_rule_path($css_rule['crid'])), 'theme', $css_rule['media'], $css_rule['preprocess']);

It would be great if there was a (per-rule perhaps?) option/checkbox to 'Behave as theme CSS rule'. Then the above line of code could be changed to something like:

drupal_add_css(file_create_path(_css_injector_rule_path($css_rule['crid'])), $css_rule['behavior'], $css_rule['media'], $css_rule['preprocess']);

I guess there needs to be some updating of the css_injector.installfile as well to include something like this:

      'behavior' => array(
        'description' => 'Whether this CSS rule should behave as a theme rule',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 1),

...and the css_injector.admin.inc file to include something like this:

  $form['behavior'] = array(
    '#type' => 'checkbox',
    '#title' => t('Behave as a theme CSS rule'),
    '#default_value' => $rule['behavior'],
  );

But I honestly wouldn't know (not a module developer). Thanx in advance for considering this one.

PS: this will never get in if it remains a 'support request'. Changing it to 'feature request'.

d.cox’s picture

#9 +1

rfay’s picture

The D7 version does this, but the way it uses is not available in D6.

However, sweaver does this in D6, so following its technique would work.

jason.fisher’s picture

In Drupal 6, I believe this method may need to be used to ensure injector CSS is last:

drupal_set_html_head('<style type="text/css">' . $css . '</style>');

Injector is rather odd to use as first CSS .. end up needing way more !important markers than you should.

Denny’s picture

#10 works, thx!.

Choose 'screen' and check 'preprocess' and it works.

BTMash’s picture

While I haven't tried adding any of the other features on where the css should be loaded, I did want the css injector to be one the last things loading and for the D7 version, I am attaching the patch that seems to do the trick. I've tried it on a couple of my sites and it seems to be working just fine. However, I won't change the version since a larger focus seems on the 6.x version.

ednique’s picture

I had similar problems...
css_injector_last_loaded_455246_18.patch worked just fine...
to be sure I changed the weight to 200...
thanx BTMash

boclodoa’s picture

I've been using #1 + #3 + #9 for a while, but with the nitobe theme that does not work. I think the reason is that they declare as "screen" their style.css file. So what I did is to change the line

stylesheets[screen][]    = styles/style.css

to

stylesheets[all][]    = styles/style.css

in the file nitobe.info

by now is working, I'll tell you if I see troubles with this change.

emattias’s picture

Status: Active » Needs review
FileSize
1.45 KB

Here's a patch that makes css injector add css the same way that sweaver does it. This will make sure that it's added last in pretty much all cases.

rfay’s picture

Note that D7 already does this...

Also note that this change could cause unexpected changes for a large number of users, and D6 is near end of life. I'd be cautious about doing this.