How to reproduce using panels

How to reproduce:
* Add a view with a panels pane display and 2 arguments (aka contextual filters), both populated from an optional context
* Configure it with Arg1=No-context, Arg2=Some-context

Expected: View is filtered with argument2

Experienced: View is not filtered, argument2 silently ignored

How to reproduce with code

I have a view with 2 contextual filters, changed date and node type. Both filters are set up so that all values are returned if the argument is NULL. As such, I expect to be able to both arguments independently, giving 4 possible combinations:

This code demonstrates it:


  $view = views_get_view('test');

  $args = array('2011', 'paper');    // works fine, all 'paper' nodes created in 2011
  $args = array('2011', NULL);       // works as expected, all nodes created in 2011
  $args = array(NULL, 'paper');      // returns all nodes, NOT only nodes of type paper
  $args = array(NULL, NULL);         // returns all nodes as expected

  return $view->preview('default', $args);

The _build_arguments function in view.inc seems to stop whenever it encounters an argument that is not obtained from the url and has no value. Subsequent arguments are therefore ignored.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

erik.erskine’s picture

The patch seems to work for me, though I'm not totally sure what the $status variable means, so perhaps someone can verify it.

Thanks!

dawehner’s picture

tim.plunkett’s picture

@ingaro, one option you have now is to use "Fixed" and provide the default value of "all", which matches the wildcard and would show all results.
Or, you can try the patch in #1272688-10: Add new argument default action that uses wildcard as default value and use the new action, "Use the wildcard to display all results".

I think your patch makes sense, but could break existing sites in unexpected ways, and merlinofchaos has convinced me that adding a new action is the way to go.

erik.erskine’s picture

Thanks @tim.plunkett

The view had a content pane which was getting 6 unrelated arguments from a context. I'm now passing the string 'all' rather than NULL for the arguments where I don't want to filter. This works fine without the patch in #1.

dawehner’s picture

Status: Needs review » Needs work

If the current patch changes the current behavior the status should be needs work. There are always at least 100 sites which uses a certain small feature.

Jorrit’s picture

This patch works for me. The promised default action mentioned in #3 will probably not be added.

I think the code is good because a missing argument value should not break the arguments loop but continue while there are more argument values.

Jorrit’s picture

Issue summary: View changes

better clarification of description

das-peter’s picture

I've had a similar issue: #2341249: Do not skip processing all arguments if one "fails"
However my perspective was that break; should be replaced by continue; - independent of $status.
If my patch goes in we've to decide here if $status has to be considered somehow.

geek-merlin’s picture

Title: Multiple arguments are sometimes ignored if some of them are NULL » Any argument after a missing optional one is silently ignored
Priority: Normal » Major
Issue summary: View changes

Adding to summary how this affects panels. Setting to major as this clearly satisfies "Render one feature unusable with no workaround.".

geek-merlin’s picture

Title: Any argument after a missing optional one is silently ignored » Any argument after a missing one is silently ignored
geek-merlin’s picture

Title: Any argument after a missing one is silently ignored » Any argument after a missing one is silently ignored (D7)