function _og_update_entity_fields in Organic groups 7.2
Update the field values in the entity, to reflect the membership.
This is used to allow other modules that save a new/ existing entity to act on the field values, even before hook_field_load() is called.
2 calls to _og_update_entity_fields()
- og_field_attach_insert in ./
og.module - Implements hook_field_attach_insert().
- og_field_attach_update in ./
og.module - Implements hook_field_attach_update().
File
- ./
og.module, line 931 - Enable users to create and manage groups with roles and permissions.
Code
function _og_update_entity_fields($entity_type, $entity) {
list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
if (!og_is_group_content_type($entity_type, $bundle)) {
return;
}
$wrapper = entity_metadata_wrapper($entity_type, $entity);
foreach (og_get_group_audience_fields($entity_type, $bundle) as $field_name => $label) {
$field = field_info_field($field_name);
$gids = array();
if ($field['cardinality'] == 1) {
if ($og_membership = $wrapper->{$field_name . '__og_membership'}
->value()) {
// Wrapper return an array.
$gids = $og_membership[0]->gid;
}
}
else {
$target_type = $field['settings']['target_type'];
$gids = og_get_entity_groups($entity_type, $entity, array(), $field_name);
$gids = !empty($gids[$target_type]) ? array_values($gids[$target_type]) : array();
}
if ($gids) {
$wrapper->{$field_name}
->set($gids);
}
}
}