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 have a view running, which shows all groups (the nodes) the user has a membership, but now I want to filter this view more specific to show only groups the user has a specific Role.
I'm using the "OG User groups", which is included inside the newest -dev. But I didn't succeeded with filtering only for the roles. I found in og.views.inc some permissions view alters, but unfortunately I'm don't have a lot of experience in creating views plugins.
I am missing something or is this functionality not yet implemented?
Thanks
Comment | File | Size | Author |
---|---|---|---|
#18 | og_roles.patch | 6.15 KB | fago |
#17 | Google Chrome.jpg | 206.61 KB | amitaibu |
#13 | og_roles.patch | 4.93 KB | fago |
#11 | og-roles-in-views-1164516-11.patch | 4.88 KB | matt2000 |
#9 | group_roles_filter.zip | 2.07 KB | tehbmar |
Comments
Comment #1
amitaibu> but now I want to filter this view more specific to show only groups the user has a specific Role.
This doesn't exist yet. Postponed until after 7.x-1.1 is out.
Comment #2
Gemma Morton CreditAttribution: Gemma Morton commentedI have attached a patch which uses the og_user_roles table to help you filter by Users with Roles in a Group. It also has a Numeric Argument filter which *should* work, and a Field which instead of using field_data uses this table too. Please test and commit if it works for you. I spent well over a day figuring this out. There is probably a lot of other work that can be done to improve this integration but for the purposes of having a Filter in your View, and Field of Roles, this is sufficient.
Comment #3
Gemma Morton CreditAttribution: Gemma Morton commentedChanged Status to "Needs Review" as I dont want this getting lost in the Postponed Queue.
Comment #4
amitaibuI think we should postponed it after 1.1 is out (which should happen in a few days , if everything goes well), as Roles the and permissions might become an entity, to allow more flexibilty, so also the Views part will change.
Comment #5
Gemma Morton CreditAttribution: Gemma Morton commentedOk, that's fine. This patch doesn't work as well I had hoped anyway. It's a starting point though, for anyone who wants to take a crack at it. It's broken my brain for too long now, and I need to get going with something that works, so for now Im just going to use a "Views Query Alter" hook.
---
Changed status back to postponed
Comment #6
amitaibu@mckeen.greg ,
OK, thanks for the work.
Comment #7
wjaspers CreditAttribution: wjaspers commentedHere's a simple patch that adds the "group role" data to Views.
Comment #8
wjaspers CreditAttribution: wjaspers commentedHere's a p0 patch so it can be applied in drush make, too.
Comment #9
tehbmar CreditAttribution: tehbmar commentedWith some code from the patches
http://drupal.org/files/issues/og-user-roles.patch written by @mckeen.greg
and
http://drupal.org/files/issues/og-roles-in-views-1164516-7.p0.patch written by @wjaspers
and help from @matt2000 we wrote a module that creates a filter that allows you to filter by group roles and actually lists the roles to filter by.
Matt will be contributing a patch that will add this modules functionality to OG itself. But until then you guys get a stand alone module.
Comment #10
mrfelton CreditAttribution: mrfelton commentedI was looking for OG Roles support in Views, but as an access check rather than as a filter...
Comment #11
matt2000 CreditAttribution: matt2000 commentedHere's the patch as promised in #9
Comment #12
amitaibuNote that this experimental branch might solve it #1261376: Entity-ify Roles
Comment #13
fagook, looks like that experimental branch is deprecated.
I've tried the patch from #11 and noted incorrect results, as views does not pick up both joins listed for the table. Afaik there is no way in views to join the table from both tables, in particular when joining from another relationship.
To make it work, I've just fixed the handler to add the constraint to any (foreign) user relationship. So you can relate your membership entities somehow with users, to which the user-roles are then associated.
I tried to filter or list user roles for a og-members view, thus joining from users to og-memberships. In that scenario the existing og-roles field resultet in duplicates as the field-table was not in any use yet. The same behavior resulted when using the new og-roles field introduced by #11 . To fix that, I've moved the field to the og_membership table. However, that way just selecting user.uid via additional fields does not work, as there is no way to join back to the users table for views (it's a relationship!). Thus, I had to fix it to just make use of an existing relationship too.
Also, patch added fields for gid and uid again - what's not usual in views, so I've removed that.
Patch attached what allows me to create a view
* listing users, relating to og-memberships - thus restrict users by membership of a certain group
* show og user roles for that users + allow filtering by og user role
Comment #14
fagooh, I forgot a point:
I removed those roles from the available options as there are no DB values for them.
Comment #16
fago#13: og_roles.patch queued for re-testing.
Comment #17
amitaibuI'm getting an error in og_handler_field_prerender_list, if there's no UID
Comment #18
fagook, I worked over the patch again to ensure it works correctly for the following cases:
* base table node, relate to membership
* base table user, relate to membership
I've improved the code to just use the first users base table, ideally I think it would be configurable which relationship should be used. However 95% probably would just have a single users relationship added, so that should do it for now.
I also fixed the errors if no users base table is there, in that case just nothing is shown / it is filtering for all users (does any user have role X in that group). I added a short note that the field requires a user relationship to work.
Also, I fixed the code excluding anonymous, authenticated roles from the roles-options + removed the argument + sort for the role-ids as they'd probably require the same tweaking as the field/filter.
Updated patch.
Comment #19
amitaibuCommitted, thanks!
Comment #21
justduet CreditAttribution: justduet commentedI'm using 7.x-1.5 and I'm having trouble filtering by OG user roles. In 'Filter Criteria', I'm filtering by 'OG user roles: Role ID' and I've selected the specific role that I'd like to include. I've noticed that the WHERE clause in the query only includes the 'og_users_roles.rid' for group (gid) = 0. Below is the query that is generated. In my case there should be also be a rid '8' from another group that is not included. I'm not sure if I'm doing something incorrect or if this is still an issue.
Edit: The intended purpose of the above View was to restrict content creation by OG Role in each group but I have since switched to 7.x-2.0-beta2 and this functionality now seems easier to achieve.
Comment #22
akalam CreditAttribution: akalam commentedI cannot see the filter when I use "Entity Reference" display type, neither using User or Organic Group Membership as base table. I see it if I use a block display type
Comment #23
martinvs CreditAttribution: martinvs commentedI have the same problem as justduet in post #21, using 7.x-1.5 and having trouble filtering by OG user roles. So I also tried to upgrade from OG 7.x-1.5 to 7.x-2.0-beta3. But I can't disable the og module because of fields that use the module (group audience) and I don't want to loose this data. Justduet, can you explain how you upgraded from OG 7.x-1.5 to 7.x-2.0-beta3.
Comment #24
crashtest_ CreditAttribution: crashtest_ commentedI believe that this has regressed on the 2.0 version of this module. Is there any way you could look at how to get the filter handler back into this branch?
Thanks!
Comment #25
dsdeiz CreditAttribution: dsdeiz commentedI think it's still there. Add a relationship for "OG Roles from membership" and select "OG user roles: Role Name" in the filter.
Comment #26
chicodasilva CreditAttribution: chicodasilva commentedThe option is there but this is still but the filter is not working as desired.
This handler also crashed with a PostGres Database.
Comment #27
joachim CreditAttribution: joachim commentedClosing this again:
> I think it's still there. Add a relationship for "OG Roles from membership" and select "OG user roles: Role Name" in the filter.
Yup.
> This handler also crashed with a PostGres Database.
I think it would be best to file a new bug report for this, and other follow-ons.
Comment #29
vistree CreditAttribution: vistree commentedSorry for commenting on a closed issue - but is it possible to modify the patch in a way, we can use the OG role names (not the weight!!!) for sorting?
Comment #30
vistree CreditAttribution: vistree commentedIs it better to create a new issue instead of adding such a question to a closed one?