How can I programatically load a group? I have written this code to render a list of profiles (using the Profile module). It works fine.

// render profiles
$accounts = \Drupal\user\Entity\User::loadMultiple($uids);
$storage = \Drupal::entityTypeManager()-&gt;getStorage('profile');
if (!empty($storage)) {
  foreach ($accounts as $account) {
    $profiles[] = $storage-&gt;loadByUser($account, 'profile');
  }
  if ($profiles) {
    $content = \Drupal::entityTypeManager()
      -&gt;getViewBuilder('profile')
      -&gt;viewMultiple($profiles, 'teaser');
  }
}


I have applied the same logic to rendering a list of groups (using the Group module). It fails with the error below.

// render groups
$groups = \Drupal\group\Entity\Group::loadMultiple($ids);
$storage = \Drupal::entityTypeManager()-&gt;getStorage('group');
if (!empty($storage)) {
  foreach ($groups as $group) {
    $test[] = $storage-&gt;loadByGroup($group, 'my_group');  // FAILS HERE
  }
  /* if ($groups) {
    $content = \Drupal::entityTypeManager()
      -&gt;getViewBuilder('group')
      -&gt;viewMultiple($group, 'teaser');
  } */
}



  Fatal error: Call to undefined method Drupal\Core\Entity\Sql\SqlContentEntityStorage::loadByGroup()


What method should I use to load a group? or how should I programatically load a group?

Thanks
Adding my comment as an answer:

$groups = \Drupal\group\Entity\Group::loadMultiple($ids); is all that is needed to load the groups based on IDs. Group::loadMultiple() does the storage bits already, so no need to duplicate the work.

So the full snippet would be something like:

&lt;?php

$groups = \Drupal\group\Entity\Group::loadMultiple($ids);
if ($groups) {
  $content = \Drupal::entityTypeManager()
      -&gt;getViewBuilder('group')
      -&gt;viewMultiple($group, 'teaser');
}