What is the correct way to create a group for a defined group type.
Is it correct to do it like this?

$group_to_create= \Drupal::entityTypeManager()->getStorage('group')->create(['type' => '<TheMachineNameOfTheGroupType>']);
$group_to_create->save();

How can the title/label be defined while creating the group?

Thanks for helping!

Comments

JD_1 created an issue. See original summary.

dbielke1986’s picture

Status: Active » Fixed

This is the way it is working for me:

$group_to_create= \Drupal::entityTypeManager()->getStorage('group')->create(['type' => '<TheMachineNameOfTheGroupType>']);
$group_to_create->set('label', '<TheLabel>');
$group_to_create->setOwner(\Drupal\user\Entity\User::load('<UID>'));
$group_to_create->save();

Status: Fixed » Closed (fixed)

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