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.
How can we pass the group arguments in Views? It's super easy with 6.x but I can't find it with 7.x.
Comment | File | Size | Author |
---|---|---|---|
#24 | Picture 94.png | 51.43 KB | petednz |
#23 | view.png | 13.88 KB | medden |
#18 | og_viewscontext.zip | 2.54 KB | torrance123 |
Comments
Comment #1
Swebmas CreditAttribution: Swebmas commentedComment #2
Swebmas CreditAttribution: Swebmas commentedComment #3
geerlingguy CreditAttribution: geerlingguy commentedI second this request.
Comment #4
amitaibuIn D6 the group Id == node ID. But this is not the case in D7. So either you do it manually via Views API, or you use a module such as OG-context to pass that group for you.
In brief:
Comment #6
geerlingguy CreditAttribution: geerlingguy commentedHow could I do the opposite of what you did in #4? For example, I have a group ID, and I want to get the nid of the group's node... is there a way to do that without making a DB query to find it myself?
For example, right now, to get a view to show up on a group page, but displaying some content in the group's node, I have the following my argument validation, to get the nid from the gid:
(For my reference: http://archstldev.com/node/793).
Comment #7
amitaibuComment #8
amitaibu$group = og_load($gid);
Comment #9
amitaibuComment #10
geerlingguy CreditAttribution: geerlingguy commentedWoah. Cool - didn't know about og_load(). Very nice!
Comment #11
Sol Roth CreditAttribution: Sol Roth commentedI have a view with the argument Fields: group_audience - gid (it's displaying a contest_entry content type which allows members of the group to vote on each node.)
In the group node, I have a field in the group that is a select list containing the stage of the contest (open for voting etc). How do I filter the view to only show up when the contest is in the voting stage (the contest stage field is selected to "voting" on the group node)? I'm dealing with a bug with minipanels (http://drupal.org/node/1049154), so I'm hoping to accomplish this entirely with views.
Would using a custom php validator be a good way to accomplish this?
Comment #12
Sol Roth CreditAttribution: Sol Roth commentedJust incase anyone needs this or had some input / a better way. I accomplished what I needed to do by using the argument
Fields: group_audience-gid with "provide default argument" and
Default arguement type
"Current group from context"
In Validator I choose "PHP Code"
$group = og_load($argument);
$node = node_load(($group->etid));
if ($node->field_contest_stage['und'][0]['value']=='Voting'){return TRUE;}
Comment #13
neopoet CreditAttribution: neopoet commentedApologies for hijacking this thread, but my question is similar --
How do you get a group ID if you only have a node that has been associated with that group (the node has been "submitted into" the group, and is not the group node itself)?
Thank you very much.
Comment #14
gilzero CreditAttribution: gilzero commentedSubscribe
Comment #16
torrance123 CreditAttribution: torrance123 commentedI'm reopening this ticket as php code inside a views argument is not the correct solution.
USE CASE: I want to add a tab to my group node that pulls in a list of fields from the nodes that are associated with my group. Normally, I would set the view path to 'node/%/view', and set the argument appropriately. But since nid != gid, I cannot filter out nodes that are not audience to this node.
Comment #17
torrance123 CreditAttribution: torrance123 commentedIf it helps others, we solved this by using the context filter "Fields: group_audience - gid" and then additionally creating a tiny module which uses hook_views_pre_view() to translate the nid to the group ID, if it exists.
We had three views that needed this translation. This was the little bit of module code we used (module called 'vapi'):
Ideally, this would be an generic contextual filter rather than running as an adhoc hook_views_pre_view(), but I don't know how to do that as yet.
Comment #18
torrance123 CreditAttribution: torrance123 commentedYay, I managed to write a contextual filter (albeit with the field name hardcoded [field_data_group_audience]). If, for example, you are at /node/%/viewspage, and you want to load all nodes that are members of the group represented by the wildcard, this will do the trick.
Comment #19
greta_drupal CreditAttribution: greta_drupal commented@torrance123 : I have the same use case. Did you find a solution? Might it work with D6.22? Would you mind expounding on your "normally, I would..." approach? The the path settings for my views node tabs are tripping me up.
Comment #20
medden CreditAttribution: medden commentedI found a very simple way to pass current OG as an argument in views.
It works for both adding new content to a group.
e.g. url
node/add/group_post?gids_node[]=1&destination=node/1
and also for editing existing group content.
e.g. url
node/16/edit
Inside any view, add a relationship for (Content) Group membership: Node group membership
Then add a contextual filter/argument for (group membership) OG membership: Group gid
Under the settings select Provide default value
Type PHP contextual filter code
Code:
I got this to work for setting organic group permissions for the new view tab on the media module library browser (media-2-x). Now each group has it's own library of files!
Comment #21
enricperaThanks medden,
It works for us!!!!
Comment #22
petednz CreditAttribution: petednz commentedCould either medden or creatcat flesh out the steps so I can see why i am missing any such Relationship.
View is of type 'content' using Views3 on D7
WHen I look under Relationships I do not see any with word 'membership'
Ditto now options under Contextual Filters with the word 'membership'
So maybe I am missing something way back at the Group Field Settings? WHat I have is
Group - Node entity
- Group type
- Group visibility
and
Post - Node entity
- Groups audience
- Group content visibility
Thanks for any pointers/screenshots you can offer
Comment #23
medden CreditAttribution: medden commentedHi petednz,
Are you sure you are looking in 'relationships' and not in 'contextual filters'?
I know OG module has renamed some of it's terms, but I'm using OG-7.x-1.3 and also have most of the modules, like 'access control' enabled. Perhaps it's a sub module that gives the membership relationships.
I've attached an image of my add relationship form so you can see.
Comment #24
petednz CreditAttribution: petednz commentedalways happy to have fundamental questions asked - but yes in this case i am not confused - here is what i see
Comment #25
chintan4u CreditAttribution: chintan4u commentedhello torrance123,
Your module saved me from disaster.
Thanks a lot.
Comment #25.0
chintan4u CreditAttribution: chintan4u commentedundoing comments. not sure how the heck they got added to original post