I need to use the contextual filters in the reference dialog view to show only nodes that belongs to specific groups (use of the og-module).
In this special case nodes that belongs to groups of the logged-in user.
The views-preview shows me the right results but the reference-dialog-search window has no results?!
This happens even when i define a fixed default value in the contextual filter.
Some ideas?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

fabsor’s picture

This would be very hard to do, since we need to inform the view of the contextual filters somehow. I have to think a little on this one.

Soul88’s picture

Is there a chance I can load context of OG I'm adding the node to?

I need to filter a list of nodes according to some fields that are stored in OG. And also according to the type of the node I'm creating (same field is shared among different node types)

stupiddingo’s picture

It depends on the specific problem you are trying to solve, but I have discovered some pretty elaborate (albeit hackish workarounds) solutions you can derive using a Filter Criteria of User: Current (Yes) tied to Relationships.

Here is an example based on the standard OG_Content View of new group nodes based on the group memberships of the current user without using contextual filters.
View of group nodes based on current users group memberships without using contextual filters

There is certainly performance implications, but since we're only using this view in an editing popup, I'm not overly concerned.

A simpler example would be to add a relationship to user based on authorship or revisions and then set the filter criteria to (user) User: Current (Yes) to get nodes authored/revised.

This is definitely a workaround and doesn't solve the problem per se, but I thought I'd share a solution for some use cases where we would typically use contextual filters.

tostinni’s picture

@fabsor is there a technical reason for references dialog not being able to use contextual filters ?
If so, is there another possibility to dynamically pass some arguments to the view ?
I was trying to add some to the url of the search button, but adding a contextual filter to the view raise the results bug.

Thanks.

kalpeshhpatel’s picture

Hello there, I had the same problem as I wanted to list titles that belongs to current logged-in users only.

I managed to resolve it by using filters as follows:

(It requires Views PHP modules to be installed.)

1) Selected Filters
2) From the available options I selected "Global: PHP"
3) After that I added following code in Filter Code section.

if($row->uid != $GLOBALS['user']->uid)
   return TRUE;
else
   return FALSE;

4) Saved the view.

It resolved my problem and worked as expected.

I know that this is not workaround for the bug, but I though this may help someone having similar issue.

adaddinsane’s picture

I have the same problem using OG to filter. The workaround in #5 has nothing to do with the OG issue.

Actually it's a genuine bug in the code, because there is absolutely no reason why an embedded view can't handle arguments, it can.

My client (I'm a contractor, solving this was part of my day job) is using SVN so I can't do a proper patch but it's really simple. This:

function references_dialog_search_view($view_name, $display_name, $attachable) {
  $args = func_get_args();
  $args = array_splice($args, 2);
  $view = views_get_view($view_name);

Should be:

function references_dialog_search_view($view_name, $display_name, $attachable) {
  $args = func_get_args();
  $args = array_splice($args, 3); // <--------- Must remove "$attachable" as well.
  $view = views_get_view($view_name);

Obviously a left-over from when the function had two arguments.

Now it works perfectly.

Edit: in fact the "array_splice" would more logically be "array_slice" since we're not doing any replacement.

oranges13’s picture

Thank you @adaddinsane! Here's a patch with his fix, verified working on my installation.

oranges13’s picture

Status: Active » Needs review
xamanu’s picture

Status: Needs review » Reviewed & tested by the community

Works fine for me. Thank you oranges13!

  • rogical committed 746a40d on 7.x-1.x authored by oranges13
    Issue #1340642 by intervalle: Contextual filters - no results at all
    
rogical’s picture

Version: 7.x-1.0-alpha1 » 7.x-1.x-dev
Issue summary: View changes
Status: Reviewed & tested by the community » Fixed

fixed in dev

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.