Skip to content
This repository has been archived by the owner on Aug 18, 2024. It is now read-only.

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

Open
beerbaitandfishing opened this issue Jan 15, 2018 · 6 comments

Comments

@beerbaitandfishing
Copy link

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 ).

@MPParsley
Copy link
Collaborator

MPParsley commented Jul 23, 2018

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.

@meecect
Copy link

meecect commented Jul 26, 2019

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
Copy link

meecect commented Jul 26, 2019

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.

@semiaddict
Copy link

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

@cofihouse
Copy link

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.

@bohemier
Copy link

@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',
  ];

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants