You are here

function og_field_write in Organic groups 7

Insert or update a field record.

DEPRECATE WHEN FIELD SCHEMA CAN BE CHANGED.

Since we can not change the field schema we must still populate the fields with non-null values.

Parameters

$op: The operation - "insert" or "update".

2 calls to og_field_write()
og_field_insert in ./og.field.inc
Implements hook_field_insert().
og_field_update in ./og.field.inc
Implements hook_field_update().

File

./og.field.inc, line 408
Field module functionality for the Organic groups module.

Code

function og_field_write($op, $entity_type, $entity, $field, $instance, $langcode, &$items) {
  $wrapper = entity_metadata_wrapper($entity_type, $entity);
  $group_memberships = array();
  foreach ($wrapper->og_membership
    ->value() as $group_membership) {
    $group_memberships[$group_membership->gid] = $group_membership;
  }
  foreach ($items as &$item) {
    $gid = $item['gid'];
    if (!empty($group_memberships[$gid])) {
      $item['state'] = $group_memberships[$gid]->state;
      $item['created'] = $group_memberships[$gid]->created;
    }
    else {
      $item += array(
        'state' => OG_STATE_ACTIVE,
        'created' => time(),
      );
    }
  }
}