Created
April 29, 2014 15:51
-
-
Save codexmas/11404313 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/docroot/profiles/commons/modules/contrib/og/includes/og.membership.inc b/docroot/profiles/commons/modules/contrib/og/includes/og.membership.inc | |
index 5691354..daa6014 100644 | |
--- a/docroot/profiles/commons/modules/contrib/og/includes/og.membership.inc | |
+++ b/docroot/profiles/commons/modules/contrib/og/includes/og.membership.inc | |
@@ -23,8 +23,8 @@ class OgMembership extends Entity { | |
throw new OgException('OG membership can not be created for anonymous user.'); | |
} | |
- $wrapper = entity_metadata_wrapper($entity_type, $etid); | |
- $bundle = $wrapper->getBundle(); | |
+ $entity = !empty($this->entity) ? $this->entity : entity_load_single($entity_type, $etid); | |
+ list(,, $bundle) = entity_extract_ids($entity_type, $entity); | |
$group_type = $this->group_type; | |
$gid = $this->gid; | |
diff --git a/docroot/profiles/commons/modules/contrib/og/og.module b/docroot/profiles/commons/modules/contrib/og/og.module | |
index 674e1e1..c153d4f 100755 | |
--- a/docroot/profiles/commons/modules/contrib/og/og.module | |
+++ b/docroot/profiles/commons/modules/contrib/og/og.module | |
@@ -974,9 +974,9 @@ function _og_update_entity_fields($entity_type, $entity) { | |
} | |
} | |
else { | |
- foreach ($wrapper->{$field_name . '__og_membership'}->value() as $og_membership) { | |
- $gids[] = $og_membership->gid; | |
- } | |
+ $target_type = $field['settings']['target_type']; | |
+ $gids = og_get_entity_groups($entity_type, $entity, array(), $field_name); | |
+ $gids = !empty($gids[$target_type]) ? $gids[$target_type] : array(); | |
} | |
if ($gids) { | |
$wrapper->{$field_name}->set($gids); | |
@@ -1827,15 +1827,29 @@ function og_membership_access($op, $entity, $account = NULL, $entity_type = 'og_ | |
* The entity type. | |
* @param $entity | |
* The entity object, or the entity ID. | |
+ * | |
+ * @return | |
+ * TRUE or FALSE if the entity is a group. | |
*/ | |
function og_is_group($entity_type, $entity) { | |
- $wrapper = entity_metadata_wrapper($entity_type, $entity); | |
- $bundle = $wrapper->getBundle(); | |
+ if (is_numeric($entity)) { | |
+ $entity = entity_load_single($entity_type, $entity); | |
+ } | |
+ | |
+ list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity); | |
if (!field_info_instance($entity_type, OG_GROUP_FIELD, $bundle)) { | |
return variable_get("og_is_group__{$entity_type}__{$bundle}", FALSE); | |
} | |
- return !empty($wrapper->{OG_GROUP_FIELD}) && $wrapper->{OG_GROUP_FIELD}->value(); | |
+ | |
+ $items = field_get_items($entity_type, $entity, OG_GROUP_FIELD); | |
+ | |
+ if (is_array($items)) { | |
+ return (bool) $items[0]['value']; | |
+ } | |
+ else { | |
+ return $items; | |
+ } | |
} | |
@@ -2062,6 +2076,9 @@ function og_group($group_type, $gid, $values = array(), $save_created = TRUE) { | |
} | |
if (empty($og_membership->is_new) || $save_created) { | |
+ // Pass the entity object along to OgMembership::save() so we don't have | |
+ // to reload it. | |
+ $og_membership->entity = $entity; | |
// Save the membership for update, or if the OG membership is new when | |
// "save-created" is TRUE. | |
$og_membership->save(); | |
@@ -3539,14 +3556,13 @@ function og_get_groups_by_user($account = NULL, $group_type = NULL) { | |
$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(); | |
+ $og_memberships = og_get_entity_groups('user', $account->uid); | |
if (!$og_memberships) { | |
return; | |
} | |
- foreach ($og_memberships as $og_membership) { | |
- $gids[$og_membership->group_type][$og_membership->gid] = $og_membership->gid; | |
+ foreach ($og_memberships as $entity_type => $group_id) { | |
+ $gids[$entity_type] = $group_id; | |
} | |
if (empty($group_type)) { | |
diff --git a/docroot/profiles/commons/modules/contrib/og/plugins/entityreference/behavior/OgBehaviorHandler.class.php b/docroot/profiles/commons/modules/contrib/og/plugins/entityreference/behavior/OgBehaviorHandler.class.php | |
index 40781b2..14b76ad 100644 | |
--- a/docroot/profiles/commons/modules/contrib/og/plugins/entityreference/behavior/OgBehaviorHandler.class.php | |
+++ b/docroot/profiles/commons/modules/contrib/og/plugins/entityreference/behavior/OgBehaviorHandler.class.php | |
@@ -27,7 +27,7 @@ class OgBehaviorHandler extends EntityReference_BehaviorHandler_Abstract { | |
} | |
$id = $wrapper->getIdentifier(); | |
$items[$id] = array(); | |
- $gids = og_get_entity_groups($entity_type, $entity, array(OG_STATE_ACTIVE), $field_name); | |
+ $gids = og_get_entity_groups($entity_type, $entity, array(), $field_name); | |
if (empty($gids[$target_type])) { | |
continue; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment