These errors have to do with context module and css_injector module not getting along. Could some one with a little php knowledge help me fix this?
Fatal error: Call to undefined function file_create_path() in /home/content/58/7409458/html/sites/all/modules/context/plugins/context_reaction_css_injector.inc on line 27
after the code change below I get this error:
Notice: Undefined offset: 0 in _css_injector_load_rule() (line 163 of /home/content/58/7409458/html/sites/all/modules/css_injector/css_injector.module).
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_rule['file_path']), 'module', $css_rule['media'], $css_rule['preprocess']);
}
}
}
}
}
}
Not knowing a lot about php I changed the following after looking up the fuction for line 27 on drupals site and seeing that it was still using a drupal 6 function. Code may not even be close but it got rid of the error on contexts side and brought up a new error.
drupal_add_css(file_create_path($css_rule['file_path']), 'module', $css_rule['media'], $css_rule['preprocess']);
to
php drupal_add_css('sites/default/files/css_injector/' . $css_rule);
The code for the css_injector module is quite a bit longer but the error falls into an if statement. Not that the code may need to be changed elsewhere but I'll just post that section for now. Specifically the error targets the line of the first return.
if (is_numeric($crid)) {
return $rules[$crid];
}
else {
return $rules;
}
}
Any help or being pointed in the right direction would be greatly appreciated. I'm going to post this bug to css_injector's page as well considering it seems to be a bug between the two modules working together.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | d7-css-injector-fix-1132842-6.patch | 846 bytes | wbobeirne |
| #4 | d7-css-injector-fix-1132842-4.patch | 845 bytes | wbobeirne |
Comments
Comment #1
new2lw commentedHere's the whole function that the if statement is in. The undefined offset error comes up in the first return of the last if statement.
Comment #2
wjaspers commentedsubscribing
Comment #3
Anticosti commentedI just encountered the same issue :(
I really need this to work.
Can anyone have a look into this for us.... please :(
Let's hope a fix will come soon.
Cheers,
Comment #4
wbobeirne commentedIt was a really simple fix, this plugin just didn't get tested in the move to Drupal 7. file_create_path() was removed in d7, so I used the file_create_filename() function instead.
Attached is a patch that should work.
Comment #5
wjaspers commentedThere's a tab on the line which begins with $path. Please update this to use spaces. Otherwise, this patch looks good.
Comment #6
wbobeirne commentedAh, slipped by me. Here's a tabless patch.
Comment #7
tekante commentedFixed with commit http://drupalcode.org/project/context.git/commit/be834259593b07b7c58ac31...
Provided patch was adjusted to ensure that only rules enabled in the context resulted in additions and to leverage the css injector module to get the correct path to the saved css file.
Note that the commit message incorrectly identifies this as issue 1770846 (wbobeirne's uid)