Problem/Motivation

I have created a user named as "group_admin" with Administer group permission. group_admin logged in and added a group.
Then go the membership page, it's showing two member records with same username but different group_content ID.

Expected result

No need to show duplicate entries in the members page

Comments

syammohan_zyxware created an issue. See original summary.

Jonah Fenn’s picture

I'm encountering this issue as well.

When I attempt to remove either one of them it gives me a white screen.

In the limited testing that I've done, this has occurred when I'm adding and trying to remove the user-1 account. I'm able to add other accounts that are not user-1 and they add singly. I'm unable to remove any of the users from a group, however.

maticb’s picture

Issue seems to be with the (src/Entity/Form/)GroupContentForm.php, actions():111, there we have this code:

 // Make sure we complete the wizard before saving the group content.
        $index = array_search('::save', $actions['submit']['#submit']);
        array_splice($actions['submit']['#submit'], $index, 0, '::complete');

which produces an array containing ["::submitForm", "::complete", "::save"], where the last two callbacks are the cause of the duplicates.

The issue here seems to be in replacing using array_splice() where the third parameter(length) should be 1?

        array_splice($actions['submit']['#submit'], $index, 1, '::complete');

This fixes the immediate problem, but I do not know if it can break any other forms.

EDIT: @fenns, for the removal issues, you can probably fix it with the patch from here: https://www.drupal.org/project/group/issues/2908830

maticb’s picture

Status: Active » Needs review
mmbk’s picture

I had the same problem, and can confirm, that this patch ist solving it.

@maticb many thanks for fixing it :-)

Jonah Fenn’s picture

Tested the patch. It works great.

Thanks for your work @maticb, and also for the tip on the content removal patch!

dravenk’s picture

Status: Needs review » Reviewed & tested by the community

test++.
no longer members duplicated when create a new group.

bowevil’s picture

Tested the patch using Drupal 8.4.2 and php 7.0.
No duplicate members when creating a new group or a new user is added to group.
Thanks @maticb.

lblissett’s picture

Yes, i can confirm this. No longer duplicate members with this patch.
Durpal 8.5.3 / PHP 7.1

@maticb: Thanks a lot!

Deno’s picture

Guess i'm stating the obvious, but this patch has not made it to rc2. that is, the bug persists in this pre-release.

kristiaanvandeneynde’s picture

Status: Reviewed & tested by the community » Needs work

This patch could do with a test that confirms it is broken now and is fixed after the patch is applied.

As far as I can remember, we need the order of submit handlers to be ["::submitForm", "::complete", "::save"], because:

  • submitForm() builds the entity from step 2
  • complete() saves the entity from step 1 and adds it to the entity from step 2
  • save() saves the entity from step 2, which now has a reference to the entity from step 1

So removing complete() from the submit handlers is ill-advised as it will break the linking of the group content.

kristiaanvandeneynde’s picture

Status: Needs work » Needs review
StatusFileSize
new3.97 KB

Here we go, this shows where it goes wrong. Now we need to figure out why.

Status: Needs review » Needs work

The last submitted patch, 12: group-2923297-12-TEST_ONLY.patch, failed testing. View results

kristiaanvandeneynde’s picture

Status: Needs work » Needs review

The offending code is in Group::postSave()

  /**
   * {@inheritdoc}
   */
  public function postSave(EntityStorageInterface $storage, $update = TRUE) {
    parent::postSave($storage, $update);

    // If a new group is created and the group type is configured to grant group
    // creators a membership by default, add the creator as a member.
    // @todo Deprecate in 8.x-2.x in favor of a form-only approach. API-created
    //   groups should not get this functionality because it may create
    //   incomplete group memberships.
    $group_type = $this->getGroupType();
    if ($update === FALSE && $group_type->creatorGetsMembership()) {
      $values = ['group_roles' => $group_type->getCreatorRoleIds()];
      $this->addMember($this->getOwner(), $values);
    }
  }

This means the complete handler saves the group (which creates the member) and then creates the member again in the save handler.

kristiaanvandeneynde’s picture

StatusFileSize
new7.64 KB

This should fix it, but introduces a behavioral BC break, so I'm not too sure about this.

Status: Needs review » Needs work

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

maticb’s picture

@kristiaanvandeneynde, if you say that the "::complete" step cannot be removed, then what was the prupose of this code in the first place?

 array_splice($actions['submit']['#submit'], $index, 0, '::complete');

it doesn't really do anything, so I assume you can remove it then?

kristiaanvandeneynde’s picture

It adds ::complete to the array after $index position, see the last bit of example #1 of array_splice(): http://be2.php.net/manual/en/function.array-splice.php

phjou’s picture

I had the same problem and it occurs on the 8-x-2-x branch when you check both "The group creator automatically becomes a member" and "Group creator must complete their membership".

It makes sense in a way, you add the creator automatically as a member and you also have to complete the membership. We should probably just check that the complete membership option is not enabled before creating automatically the membership of the creator.

I disabled one of the feature in order to avoid the bug.

lobsterr’s picture

I think we have a duplication here #3016197: "Group creator must complete their membership" Wizard duplicates membership
I have proposed a solution https://www.drupal.org/files/issues/2019-03-01/group_membership_duplicat...
I add setCreatorGetsMembership method which controls whether we should create a user or not. Basically, I set it to false, when we use a wizard.

alxshell’s picture

#19 is fixing it. Thx @phjou

lobsterr’s picture

Status: Needs work » Closed (duplicate)
Related issues: +#3016197: "Group creator must complete their membership" Wizard duplicates membership

I'm closing this issue as duplicate. kristiaanvandeneynde proposed a nice solution in #3016197: "Group creator must complete their membership" Wizard duplicates membership