og icon indicating copy to clipboard operation
og copied to clipboard

Fix for being able to relate content from the logged in user ( drupal 8.3 )

Open beerbaitandfishing opened this issue 8 years ago • 6 comments

Add the following to the file - modules/contrib/og/og.views.inc

-----Add ------

$data['og_membership']['node']['relationship'] = [ 'real field' => 'entity_id', 'base' => 'node', 'base field' => 'nid', 'label' => t('OG Membership Content'), 'title' => t('OG Membership Content'), 'id' => 'standard', ];

Add that under the existing relation between user and og_membership.

Then you should be able to go from user -> og membership -> content ( the group that they're a member of ).

beerbaitandfishing avatar Jan 15 '18 20:01 beerbaitandfishing

Hi @beerbaitandfishing, I created a PR in #415.

This relation might be useful but isn't this issue a duplicate for #254? You'd want to use a contextual filter to list all the content for the current user.

MPParsley avatar Jul 23 '18 08:07 MPParsley

I thought #254 was more about getting content from groups that a user is a part of. I think this issue is just about being about to get the group node from the og membership entity.

I found this issue while I was trying to create a view that showed the groups a user belonged to. The familiar relationship from the the 7.x branch aren't here anymore so I'm a bit lost as to how to create the view.

When I add this code, I do see the new 'OG Membership Content' Relation and I have added it, however, I do not get many (any?) additional fields to add to my view. I was expecting to see things like 'title' and the rest of the fields on the group node bundle that I could specify to use the relationship, but they aren't there.

I can chose 'rendered entity' but then I have to choose a view mode. I think it would be useful to just render individual fields.

meecect avatar Jul 26 '19 03:07 meecect

anyway, for my case, I thought I might as well add another relation, relating the group to the og membership, then the membership to the user, then filtering on the user. I did that by adding this:

$data['node']['og_membership']['relationship'] = [ 'real field' => 'nid', 'base' => 'og_membership', 'base field' => 'entity_id', 'label' => t('OG Membership'), 'title' => t('OG Membership'), 'id' => 'standard', ];

It seems to work well.

meecect avatar Jul 26 '19 04:07 meecect

I believe this would indeed be a better and more generic option than the default argument proposed in #254.

semiaddict avatar Mar 04 '20 11:03 semiaddict

I'm desperately trying to build what I think is a simple view that would show the groups a user is a active member of (visible to anyone viewing the user's profile). But this is turning out to be impossible. I've applied both this PR and #254 and I cannot figure out how to do this. This relationship doesn't appear to actually pull in the expected content fields to the view. I've added relationships user > OG:membership > og membership content but it does not expose the content's fields. The best I can get is a rendered entity and choose the view mode. But I really would like to access individual fields. But the rendered entity seems like the only (clunky) option to achieve what should be a basic feature.

cofihouse avatar Oct 14 '22 04:10 cofihouse

@cofihouse to get the full relationship with the node content, change the base table for node_field_data :

  $data['og_membership']['node']['relationship'] = [
    'real field' => 'entity_id',
    'base' => 'node_field_data',
    'base field' => 'nid',
    'label' => new TranslatableMarkup('OG Membership Content'),
    'title' => new TranslatableMarkup('OG Membership Content'),
    'id' => 'standard',
  ];

bohemier avatar May 10 '23 11:05 bohemier