Email us at info@henrytech.org to discuss your Drupal Migration today!
Add a user to group
$uid = '5';
$gid = '40';
$user = \Drupal\user\Entity\User::load($uid);
$group = \Drupal::entityTypeManager()->getStorage('group')->load($gid);
$group->addMember($user);
$group->save();
Add content to a group
$content_types_manager = \Drupal::service('opigno_group_manager.content_types.manager');
$plugin_definition = $content_types_manager->getDefinition('ContentTypeModule');
$added_entity = \Drupal::entityTypeManager()
->getStorage($plugin_definition['entity_type'])
->load($entity_id());
$group->addContent($added_entity, $plugin_definition['group_content_plugin_id']);
$group->save();

Comments