PHP 5.4 generates frequent errors in some code of mine that calls ctools_access_get_loggedin_context()
. The problem seems to be in ctools_get_context(); when called from ctools_access_get_loggedin_context(), it can get into a state where no plugin was found to handle 'entity::user', and it returns $plugin with a value of NULL. Since ctools_access_get_loggedin_context() does not check the returned value, it treats the null object as an stdObject, which raises a warning in PHP 5.4 that floats up into the UI where users can see it.
I don't understand the internals of the plugin system well enough to figure out why no plugin was found in the first place. The only thing I can think of is that I am using the ctools form wizard with anonymous user. I am also using Panels variants that need to test whether the user is logged in or not; it is difficult to tell who is checking the logged in context, since this seems to float down via the menu system.
Since I can't solve the underlying problem, at least ctools_access_get_loggedin_context() needs to handle the NULL context case gracefully. I am supplying a patch that does this, made against 7.x-1.x.
Comment | File | Size | Author |
---|---|---|---|
#13 | 2212641-13.patch | 616 bytes | joelpittet |
#8 | 2212641-ctools_anonymous_warning_fix.patch | 690 bytes | mlamothe |
Comments
Comment #1
Torenware CreditAttribution: Torenware commentedComment #2
Torenware CreditAttribution: Torenware commentedComment #3
Kojo Unsui CreditAttribution: Kojo Unsui commentedHalf similar (with php 5.3.18) : on Commons distribution, systematic warnings & notices on panelized pages, for anonymous users only :
ddebug_backtrace()
returns, so as far as I understand it seems to consider that the user is logged ?!
So I temporarily solved it applying #1 patch and adding this ugly test in
ctools_context_create_user()
(user.inc line 34)And strict warnings and notices are gone.
Comment #4
Kojo Unsui CreditAttribution: Kojo Unsui commentedOk, there is now a patch for current user context for an anonymous user.
Comment #5
DamienMcKennaComment #7
DamienMcKennaYou should only assign an issue to yourself if you're going to work on it, otherwise please leave it unassigned. Thanks :)
Comment #8
mlamothe CreditAttribution: mlamothe commentedHere is the proper fix for this issue.
Comment #9
Chris Matthews CreditAttribution: Chris Matthews as a volunteer commentedThe patch in #8 applied cleanly to the latest ctools 7.x-1.x-dev, but still needs to be reviewed and tested.
Comment #10
rayjames CreditAttribution: rayjames commentedHello, on Drupal 7.77 | PHP 5.6 | ctools 7.x-1.17 I'm getting the same error as the original poster of this issue.
"Warning: Creating default object from empty value in ctools_access_get_loggedin_context() (line 1864 of /ctools/includes/context.inc)."
I have updated to the latest version of ctools 7.x-1.17 with no luck. Do I need need to use the 7.x-1.x-dev branch to fix this? Is it going to be patched into the main branch? It's for a production site so not sure if the dev branch is ok for production. Thanks for your help and time on this.
Comment #11
DamienMcKenna@rayjames: Do you have an instance of the site besides the production one which you can test the patch on? You would need to apply the patch in #8 to fix the problem, the fix hasn't been made to the current release.
Comment #12
rayjames CreditAttribution: rayjames commentedHi @damienmckenna , that's what I ended up doing to fix it for now. Do I just keep patching each new release of the module or is this something that will get merged in? Thanks for your time and help on this.
Comment #13
joelpittetA bit of a gamble but I've committed this to the dev branch for the next release, I refactored it because it didn't need the nested conditional. I'm pretty confident this does what the patch has in it in #8.
Comment #15
joelpittet