Unverified Commit b7a6be12 authored by alesr's avatar alesr Committed by GitHub

Merge pull request #359 from jacobembree/7.x-2.x-og_get_groups_by_user

Fixes #152: Replaces NULL returns with emtpy array returns in og_get_groups_by_user()
parents 189905f5 712765b1
......@@ -16,7 +16,7 @@ before_script:
- cd ../..
# Install Drush
- composer global require drush/drush
- composer global require drush/drush:8
- export PATH=$PATH:~/.composer/vendor/bin
# Install php packages required for running Drupal
......
......@@ -3553,7 +3553,10 @@ function og_node_create_links($group_type, $gid, $field_name, $destination = NUL
* types will be fetched.
*
* @return
* An array with the group IDs or an empty array.
* If $group_type is provided then an array of group IDs matching the
* specified group type. If $group_type is not provided then an associative
* array is returned containing arrays of group IDs keyed by group type. If
* no results are found an empty array is returned.
*/
function og_get_groups_by_user($account = NULL, $group_type = NULL) {
if (empty($account)) {
......@@ -3561,18 +3564,18 @@ function og_get_groups_by_user($account = NULL, $group_type = NULL) {
$account = $user;
}
$gids = array();
if (!og_get_group_audience_fields()) {
// User entity doesn't have group audience fields.
return;
return $gids;
}
$gids = array();
// Get all active OG membership that belong to the user.
$wrapper = entity_metadata_wrapper('user', $account->uid);
$og_memberships = $wrapper->{'og_membership__' . OG_STATE_ACTIVE}->value();
if (!$og_memberships) {
return;
return $gids;
}
foreach ($og_memberships as $og_membership) {
......@@ -3581,12 +3584,10 @@ function og_get_groups_by_user($account = NULL, $group_type = NULL) {
}
}
if (empty($group_type)) {
return $gids;
}
elseif (!empty($gids[$group_type])) {
return $gids[$group_type];
if (isset($group_type)) {
return isset($gids[$group_type]) ? $gids[$group_type] : array();
}
return $gids;
}
/**
......
......@@ -105,7 +105,6 @@ class OgSelectionHandler extends EntityReference_SelectionHandler_Generic {
$field_mode = $this->instance['field_mode'];
$user_groups = og_get_groups_by_user(NULL, $group_type);
$user_groups = $user_groups ? $user_groups : array();
$user_groups = array_merge($user_groups, $this->getGidsForCreate());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment