Postponed (maintainer needs more info)
Project:
Context
Version:
7.x-3.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
12 Jul 2011 at 19:33 UTC
Updated:
28 Jul 2013 at 02:09 UTC
To reproduce I created a simple module with the following code (this is the whole .module file):
function mymodule_init() {
// Set a sitewide "node" ontext if we are on a node page
if (arg(0) == 'node' && is_numeric(arg(1))) {
$node = node_load(arg(1));
context_set('node', 'object', $node);
context_set('node', 'form', arg(2) == 'edit');
}
}
Then in my template.php I have this:
$x = context_get('node');
dpm($x);
While my context inspector shows the "node" context being created properly, the dpm() in my template.php returns an empty sting (or FALSE)
Comments
Comment #1
bleen commentedto clarify, the code in template.php is within function mymodule_process_page()
Comment #2
lucascaro commentedThe same happens to me with 7.x-3.0-beta2
I have two contexts active (I've added debug to the reactions and I can see the messages for both) but context_get and context_active_contexts return empty when I'm in a .tl.php other than page.tpl.php and html.tpl.php
Also, the inspector is not showing (at all).
It seems that the contexts get activated, and execute the reactions, but I can't see them from the theme layer (and neither does the inspector block).
Comment #3
Jason Dean commentedSame here in 7.x-3.0-beta3
context_get() and context_active_contexts() only return values when I use in theme_preprocess_page()
If I try to use them in theme_preprocess_node() or elsewhere, they return empty.
Comment #4
Jason Dean commentedIn a custom module, calling this function lists all enabled contexts:
But this lists nothing:
Perhaps it depends how late in the page load these functions are called? I'm trying to use it in a Panels visibility rule, and maybe it is calling before the active contexts are set.
Comment #5
dddbbb commented@pushka - Did you ever get anywhere with this? I'm trying to do something similar (detect context from Panels visibility rule) but it's not working for me.
Comment #6
matt2000 commentedme too. What's up?
Comment #7
bleen commentedThis is still a bug ...
Comment #8
ruuizz commentedThere is a comment on context module that indicates to call the function as late in the page load as possible. I changed the execution of my code to the end of the page load and I was able to get all the active contexts with no problem
From Context Module:
Comment #9
tekante commentedBleen, I am unable to replicate your issue using your originally provided code along with the update in comment #1. When trying to do a dpm in a MODULE_process_page function the output doesn't show until the next page load. When called from within MODULE_preprocess_page, however, it should show on the current load. Irrespective of when the dpm output shows, the actual return should be correct. If the code is outside of a function and just within the top level of template.php as your original submission seemed to indicate then a false return would be expected bacause $x would be defined before the hook_init function would run.
Can you provide any additional information?
For those looking at context_active_contexts, @ruuizz is correct about calling that as late as possible to ensure all contexts are activated which is done during various hooks depending on the conditions that activate them.
Comment #10
tekante commented