I kept getting my css injector rules loaded no matter what.

So i've made some modifications, in both modules (context and css_injector):

In Context module, file plugins/context_reaction_css_injector.inc , line 28

Replace with:

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

And in CSS Injector module, file css_injector.admin.inc, line 151

Add:

if (module_exists('context')) {
$options[] = t('Let Context Module control this CSS rule');
$description .= ' '. t('This rule will be controled by Context Module.');
}

I will now place a link to this on CSS Injector issue page.

CommentFileSizeAuthor
#3 context-6.x.3.0.zip82.56 KBhlopes
#3 css_injector-6.x-1.4.zip18.58 KBhlopes

Comments

rfay’s picture

I'm not in favor of writing specific hacks for specific modules, as mentioned in #909986-1: Enhance compatibility with Context module

milos.kroulik’s picture

This does not work for me. Maybe I'm doing something wrong?

Contents of my files:

<?php
// $Id: context_reaction_css_injector.inc,v 1.1.2.1 2009/12/14 22:34:05 yhahn Exp $

class context_reaction_css_injector extends context_reaction {

  function options_form($context) {
    $list = array();
    foreach (_css_injector_load_rule() as $css_rule) {
      $list[$css_rule['crid']] = $css_rule['title'];
    }
    ksort($list);

    return array(
      '#title' => $this->title,
      '#description' => $this->description,
      '#options' => $list,
      '#type' => 'checkboxes',
      '#default_value' => $this->fetch_from_context($context),
    );
  }

  function execute() {
    $contexts = $this->get_contexts();
    foreach ($contexts as $context) {
      if (!empty($context->reactions[$this->plugin])) {
        foreach ($context->reactions[$this->plugin] as $crid) {
          if ($css_rule = _css_injector_load_rule($crid)) {
            drupal_add_css(file_create_path(_css_injector_rule_path($css_rule['crid'])), 'module', $css_rule['media'], $css_rule['preprocess']);
          }
        }
      }
    }
  }
}
...

    if ($access) {
      $options[] = t('Add if the following PHP code returns TRUE (PHP-mode, experts only).');
      $description .= ' '. t('If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.', array('%php' => '<?php ?>'));
    }
if (module_exists('context')) {
$options[] = t('Let Context Module control this CSS rule');
$description .= ' '. t('This rule will be controled by Context Module.');
}
    $form['conditional']['rule_type'] = array(
      '#type' => 'radios',
      '#title' => t('Add the CSS on specific pages'),
      '#options' => $options,
      '#default_value' => $rule['rule_type'],
    );
    $form['conditional']['rule_conditions'] = array(
      '#type' => 'textarea',
      '#title' => t('Pages'),
      '#default_value' => $rule['rule_conditions'],
      '#description' => $description,
    );
  }

...

(removed code tag around "TRUE")

hlopes’s picture

StatusFileSize
new18.58 KB
new82.56 KB

You'll need to make changes in both modules (Context and CSS Injector). And there was a typo on one of them.

#EDIT: sorry, i'm not fully functional before coffee addition. The code you posted seems ok.

You can just download both modules already modified.

And make sure you've cleared the cache or that cache / css aggregation is disabled.

milos.kroulik’s picture

Sorry, I don't use this module anymore and don't have time right now to test it. Will report back later.

soulfroys’s picture

Unfortunately it still doesn't work...
Context 6.x-3.x-dev (2011-02-25)
CSS Injector 6.x-1.x-dev (2011-02-25)
Drupal 6.14

[ Edited: Works great! I forget "if($css_rule['rule_type']!=3)" in css_injector.module ]

hefox’s picture

Status: Needs review » Active

Please provide a patch for others to review; there's no patch here.

TimelessDomain’s picture

this is a problem for drupal 7 as well

francewhoa’s picture

Issue summary: View changes

It seems this is fixed in the latest versions. We were not able to reproduce this with:

  • Context 7.x-3.6
  • CSS Injector 7.x-1.10

If you update to the above versions but your CSS Injector rules load no matter what, in CSS Injector ensure your rules are saved but disabled. Instead enable them only in Context module.

paulocs’s picture

Version: 6.x-3.0 » 6.x-3.x-dev

I also could not reproduce using the last dev versions of Context and Css Injector for drupal 7.

As 6.x-3.x-dev is no longer supported, I'm closing it.
Please reopen it if you still have problems.

Thanks @all.

paulocs’s picture

Status: Active » Fixed
paulocs’s picture

Status: Fixed » Closed (fixed)