Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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?
Comment | File | Size | Author |
---|---|---|---|
#7 | references_dialog_contextual_filters_1340642_7.patch | 521 bytes | oranges13 |
Comments
Comment #1
fabsor CreditAttribution: fabsor commentedThis 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.
Comment #2
Soul88Is 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)
Comment #3
stupiddingo CreditAttribution: stupiddingo commentedIt 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.
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.
Comment #4
tostinni CreditAttribution: tostinni commented@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.
Comment #5
kalpeshhpatel CreditAttribution: kalpeshhpatel commentedHello 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.
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.
Comment #6
adaddinsaneI 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:
Should be:
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.
Comment #7
oranges13Thank you @adaddinsane! Here's a patch with his fix, verified working on my installation.
Comment #8
oranges13Comment #9
xamanu CreditAttribution: xamanu commentedWorks fine for me. Thank you oranges13!
Comment #11
rogical CreditAttribution: rogical commentedfixed in dev