Problem/Motivation

The method Drupal\group\Entity\Group::getRelationshipsByEntity is not filtering for the given group and returns relationships that belong to other groups other than the given one.

Steps to reproduce

Proposed resolution

Change the method implementation of Drupal\group\Entity\Group::getRelationshipsByEntity so that it filters by the given group. Probably GroupRelationshipStorageInterface needs another method for this, maybe something like loadByEntityAndGroup?

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork group-3310605

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mxh created an issue. See original summary.

lobsterr’s picture

It is not a bug, it is correct behavior. The content can belong to several groups and this methods will return all GroupRelationships, if you want to load GroupRelationships for the current group use loadByGroup

lobsterr’s picture

Ops, I was wrong, I didn't pay attention to the class! Yes, for the group it should filter by the current group. I just faced the same bug!

lobsterr’s picture

In the previous version loadByGroup accepted "filters" and getRelationshipsByEntity wrapped it with entity_id passed as a filter

lobsterr’s picture

Assigned: Unassigned » lobsterr
lobsterr’s picture

@mxh as a temp solution use loadByProperties, while I will prepare some solution

    $properties = [
      'gid' => $group->id(),
      'invitation_status' => $status,
      'plugin_id' => 'group_invitation',
      'entity_id' => $account->id(),
    ];

$this->groupRelationshipStorage->loadByProperties($properties);

This example from ginvite module. I had to use this solution.

kristiaanvandeneynde’s picture

Assigned: lobsterr » Unassigned
Status: Active » Needs review
StatusFileSize
new13.43 KB
new13.44 KB

The last submitted patch, 7: group-3310605-7-v3.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Status: Needs review » Needs work

The last submitted patch, 7: group-3310605-7-v2.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

kristiaanvandeneynde’s picture

Status: Needs work » Needs review
StatusFileSize
new13.44 KB
new13.42 KB

Status: Needs review » Needs work

The last submitted patch, 10: group-3310605-10-v3.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

kristiaanvandeneynde’s picture

Status: Needs work » Fixed

Fixed silly mistake in v3 patch on commit.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.