Posted by Jorrit on December 10, 2012 at 8:08pm
4 followers
| Project: | Chaos tool suite (ctools) |
| Version: | 7.x-1.x-dev |
| Component: | Views Content |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | reviewed & tested by the community |
Issue Summary
I have a view with a Panels Pane display with two contextual arguments. These arguments are optional and both set to retrieve their content from a Node-ID argument from the panel. In Panels I have attached these arguments to two different node-type contexts, which are optional.
When the first context is not available, the second context is passed as the first context. It think this relates to the following code in views_panes.inc:
case 'context':
$key = array_shift($context_keys);
if (isset($contexts[$key])) {
if (strpos($argument['context'], '.')) {
list($context, $converter) = explode('.', $argument['context'], 2);
$args[] = ctools_context_convert_context($contexts[$key], $converter);
}
else {
$args[] = $contexts[$key]->argument;
}
}
break;There is no } else { for the outer if. When I change it to the following, it works. The only thing is: 'all' is configurable, so this shouldn't be hard-coded, but retrieved from the view. Note: passing NULL here doesn't work.
$key = array_shift($context_keys);
if (isset($contexts[$key])) {
if (strpos($argument['context'], '.')) {
list($context, $converter) = explode('.', $argument['context'], 2);
$args[] = ctools_context_convert_context($contexts[$key], $converter);
}
else {
$args[] = $contexts[$key]->argument;
}
}
else {
$args[] = 'all';
}
break;
Comments
#1
I can confirm this issue and the fix above. Instead of 'all' it is correct to insert NULL into the array, exactly as the comment points out a few lines further down:
<?phpcase 'none':
default:
// Put in NULL.
// views.module knows what to do with NULL (or missing) arguments
$args[] = NULL;
break;
?>
#2
I recall that I tried NULL as well, that is of course the first thing that comes to mind. But it didn't work. I eventually found out where to find the default setting for the display argument, so the attached patch also works when people change 'all' to something else.
Maybe the
$args[] = NULLpart needs to be changed too.#3
I ran over the same problem. After debugging I figured that NULL does not work either, I agree that passing the exception value is a reasonable fix. Maybe Views should not stop processing if it does not find an argument, but as long as Views behaves it it does now I think that's the best fix - thus marking RTBC.
Marked #1946000: Passing optional arguments to content pane as duplicate.
I guess so, but that needs a bit more thought so unnecessary NULL values at the end are still removed before passing things on. I'd suggest committing #2 right now and handling the 'none' case in a separate issue.
#4
I believe this is a duplicate of #1917658: Empty context value results in missing argument in views argument.
The patch I supplied in the related issue does not assume 'all' but instead passes NULL as that seems to be the intended functionality in views_content_views_content_type_render() of views.inc.
Had I found this issue when searching for my problem I would have posted my patch to this issue (posted earlier the same day as the patch in #2).
#5
I don't think they are duplicates. Your patch patches 'views.inc', which handles the inclusion of all views as a pane, while my patch is on 'views_panes.inc', which only handles displays of type Panels Pane.
Fago confirmed that
NULLdoes not work like the default value. I have been digging a little deeper and I think the root cause is a bug in Views. When a missing argument is encountered inview->_build_arguments(), the loopforeach ($this->argument as $id => $arg) {is ended with a break (around line 865). Replacing that with acontinue;will allow NULLs.[edit]
I found a related Views issue: #1250336: Multiple arguments are sometimes ignored if some of them are NULL.