Index: og_role_field.module
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- og_role_field.module	(date 1481198349000)
+++ og_role_field.module	(revision )
@@ -104,28 +104,27 @@
  */
 function __og_role_field_get_roles_by_context(&$form_state = array()) {
   // Try to find the group from which we are going to load roles.
-  $groups = array();
+  $group = array();
 
-  // TODO: use og_context_determine_context('group_entity_type')
-
-  if (isset($_SESSION['og_context'])) {
+  // Try and get og_context from og_context()
+  if (!empty($og_context = og_context())) {
+    $group = $og_context;
+  }
+  elseif (isset($_SESSION['og_context'])) {
     if (is_array($_SESSION['og_context'])) {
-      $groups = array_merge_recursive($_SESSION['og_context'], $groups);
+      $group = array_merge_recursive($_SESSION['og_context'], $group);
     }
     else {
-      $groups[$_SESSION['og_context']] = $_SESSION['og_context'];
+      $group[$_SESSION['og_context']] = $_SESSION['og_context'];
     }
   }
-  // If no group exists, get the global settings
-  if (count($groups) < 1) {
-    $groups[0] = 0;
-  }
-  $roles = array();
-  $group_roles = og_role_field_role_load_from_groups($groups);
 
-  foreach ($group_roles as $index => $data) {
-    $roles[$data->rid] = $data->name;
-  }
+  // Load the group to get the bundle
+  $wrapper = entity_metadata_wrapper($group['group_type'], $group['gid']);
+  $bundle = $wrapper->getBundle();
+
+  // Get the group roles
+  $roles = og_roles($group['group_type'], $bundle, $group['gid']);
 
   return $roles;
 }
