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.
Hi,
I'm migrating members from organic groups to Groups (D7 to D8). I tried to migrate the members to Groups via migration.yml file but it is not migrating. So i'm writing a query to fetch members from D7 and add it to D7 respective groups. Do you have any services to add a member to a group programmatically?
Comments
Comment #2
dsim CreditAttribution: dsim as a volunteer commentedComment #3
sumanthkumarc CreditAttribution: sumanthkumarc at Azri Solutions commentedAFAIK, there is a addMember method in group.php.
You can load a group and then call addMember function on it.
Comment #4
dsim CreditAttribution: dsim as a volunteer commentedThanks sumanthkumarc for your input on this. It was helpful. Closing this ticket.
Comment #5
esrathi CreditAttribution: esrathi commentedI am loading the group and then calling addMember function on it, something like this:
$roles = array('test_role');
$values = ['group_roles' => $roles, 'gid' => 1];
$account = $this->createUser();
$group = \Drupal\group\Entity\Group::load(1);
$group->addMember($account, $values);
This is not adding the member to the group. Are $values and $account parameters correct here? Or is something else wrong?
Comment #6
apadernoComment #7
apaderno