I've created a page view with a contextual URL to show content from a field collection for a specific node. This works fine but I need to display this contextual link within the node itself. (The idea is that if the person viewing the node wants to see the field collections for that node tagged to a particular category, they can click on the contextual link to view that content on a separate page.) My idea is to create a view block to show a views field contextualised to the above view for the same node ID, and then expose that block within the node using Display Suite. In the master view I've added a contextual filter for the NID and a relationship to the field collection (not sure if this is necessary). In "fields" I've got the NID and "global: view". In the view field I've selected the master view as described above but no matter what I put in "contextual filters" I can't get any link to the master page view to show at all. All that shows is the "No results behaviour" text from the master view.

Comments

jenlampton’s picture

Category: Support request » Bug report
Issue summary: View changes

I'm having the same problem (tested both 1.1 and 1.0 versions of the module). My use case is quite a bit simpler, but I can confirm that contextual filters don't seem to be working for view fields.

I have a view of programs that takes a contextual filter of school_id. When the contextual filter is present, I get the correct list of programs. When the filter is not present, I see the text "filter value is NOT available " (correct empty text behavior).

I have a second view of schools. This view has fields for 1) title, 2) the school_id field (hidden) and 3) the global view field. My global view field uses the master display of the programs view, and for contextual filters I've entered the replacement pattern for school_id, [!field_school_id].

In my results, I see

the correct school title
filter value is NOT available

I have tried using a display of the programs view that is not master, but get the same results.
I have tried making the school_id field not hidden as well, but I get the same results.

The problem seems to be in get_token_value. For some reason the value returned from $view->field[$arg]->get_value($values); is a am array containing an array of values, instead of a single value we can use as a replacement pattern.

    // Collect all of the values that we intend to use as arguments of our single query.
    if (isset($view->field[$arg])) {
      switch ($token_type) {
        case '%':
          $value = $view->field[$arg]->last_render;
        break;
        case '!':
        default:
          // This is the problem, returns an array containing an array containing the value we want.
          $value = $view->field[$arg]->get_value($values);
        break;
      }
    }

It looks like the quick-fix is to use the "rendered" output instead of the raw value (that's the one with the % instead of the one with the !), in spite of all the help text telling us the contrary.

jenlampton’s picture

Title: Can't get contextual filter to work » Raw replacement patterns not working as contextual filters
baskaran’s picture

You Can use %1 and %2 or !1 and !2 . These replacement patterns will give results. It's working.

As If’s picture

My experience concurs with @jenlampton's. % works, ! does not.

Yuri’s picture

I confirm that this issue is still present: % works, ! does not.