You are here

public function OgBehaviorHandler::load in Organic groups 7.2

Implements EntityReference_BehaviorHandler_Abstract::load().

Overrides EntityReference_BehaviorHandler_Abstract::load

File

plugins/entityreference/behavior/OgBehaviorHandler.class.php, line 18

Class

OgBehaviorHandler
OG behavior handler.

Code

public function load($entity_type, $entities, $field, $instances, $langcode, &$items) {

  // Get the OG memberships from the field.
  $field_name = $field['field_name'];
  $target_type = $field['settings']['target_type'];
  foreach ($entities as $entity) {
    $wrapper = entity_metadata_wrapper($entity_type, $entity);
    if (empty($wrapper->{$field_name})) {

      // If the entity belongs to a bundle that was deleted, return early.
      continue;
    }
    $id = $wrapper
      ->getIdentifier();
    $items[$id] = array();
    $gids = og_get_entity_groups($entity_type, $entity, array(), $field_name);
    if (empty($gids[$target_type])) {
      continue;
    }
    foreach ($gids[$target_type] as $gid) {
      $items[$id][] = array(
        'target_id' => $gid,
      );
    }
  }
}