Optional Context causes Warning: Argument #2 is not an array (Ctools issue #621882 is actually a panels issue)
| Project: | Panels |
| Version: | 6.x-3.2 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
The issue opened at http://drupal.org/node/621882 seems to be a panels issue. It is related to how the default context is set up when there isn't one.
For example,
1. Create a panel page that does not have a node context
2. Create a view content pane that takes an argument, but has a default when not present (display all)
3. Add a that content pane and view the page.
You will see
warning: array_merge() [function.array-merge]: Argument #2 is not an array in .../public_html/sites/all/modules/ctools/includes/context.inc on line 197.This is related to panels/includes/plugins.inc line 50 which sets up a default context if there is none
if (!$context) {
$context = new ctools_context;
} But incoming contexts are arrays of context objects. And ctools_content_render() and it's children all expect an array of contexts. This culminates when ctools_context_optional->add_empty tries an array_merge which throws the error.
REFERNCE: http://drupal.org/node/621882

#1
Here is a patch that creates an array of a default context
#2
Y'know, every time I've passed that line I've wondered why it wasn't wrapped in an array, but I've never taken the time to properly debug and ensure that actually wrapping it in the array doesn't end up causing other problems.
How thoroughly did you test to ensure that this doesn't cause quirks elsewhere?
#3
Yeah, I wrestled with a bug on that line recently and I think that line is leftover from the very very early days of Panels 2. It Is Clearly Wrong. =)
#4
I haven't done any kind of formal testing, though we are using panels heavily on a site which is where I first saw the error/created a patch. It's got a good mix of custom content panes, views content panes, node context etc and haven't seen any other weirdness.
It seems after reading the code that the functions being handed $context all expect an array of contexts. Looks left over to me and any exposed weirdness should be fixed anyway.
#5
Good enough for me. Committed :)
#6
Automatically closed -- issue fixed for 2 weeks with no activity.