function group_entity_save in Group 7
Helper for hook_entity_insert() and hook_entity_update().
2 calls to group_entity_save()
- group_entity_insert in ./
group.entity.inc - Implements hook_entity_insert().
- group_entity_update in ./
group.entity.inc - Implements hook_entity_update().
File
- ./
group.entity.inc, line 691 - Contains all Entity API functions for the Group module.
Code
function group_entity_save($entity, $type) {
if (!empty($entity->group)) {
// Retrieve the entity id and bundle.
list($entity_id, $revision_id, $bundle) = entity_extract_ids($type, $entity);
// Load the original entity to detect changes.
$original = entity_load_unchanged($type, $entity_id);
// Gather the original and updated group ids as arrays.
$original_gids = isset($original->group) ? (array) $original->group : array();
$updated_gids = isset($entity->group) ? (array) $entity->group : array();
// Add the entity to groups that it didn't belong to earlier.
if ($gids = array_diff($updated_gids, $original_gids)) {
foreach (group_load_multiple($gids) as $group) {
$group
->addEntity($entity_id, $type, $bundle);
}
}
}
}