You are here

protected function CerPresetHandler::load in Corresponding Entity References 7.3

Loads referenced entities. This might seem like a convenience method, but it is a critical part CER's core logic.

Parameters

array $IDs: Array of entity IDs to load.

Return value

array The requested entities, wrapped by EntityDrupalWrapper. If nothing could be loaded, an empty array is returned.

2 calls to CerPresetHandler::load()
CerPresetHandler::delete in includes/CerPresetHandler.inc
Process an entity delete. Loops through the referenced entity IDs and clears their references to this entity.
CerPresetHandler::insert in includes/CerPresetHandler.inc
Process an entity insert. This loops through the referenced entity $IDs and adds a reference to this entity if the reference doesn't already have one.

File

includes/CerPresetHandler.inc, line 119
Contains CerPresetHandler.

Class

CerPresetHandler
@class Contains the logic for performing CER operations on a single entity, using a single preset.

Code

protected function load(array $IDs) {
  if (empty($IDs)) {
    return array();
  }
  $this->right
    ->rewind();
  $right = $this->right
    ->current();
  $entity_type = $right->entityType;
  $query = new EntityFieldQuery();
  $query
    ->entityCondition('entity_type', $entity_type);
  $query
    ->entityCondition('entity_id', $IDs);

  // If the right entity type has bundles, we need to filter by that too. If we don't,
  // we could run into a bug where, if the left field can reference multiple bundles,
  // we might try to modify the wrong entity. Essentially, the loading of referenced
  // entities should be as targeted as possible to prevent ambiguities and buggery.
  if ($right->isBundleable) {
    $query
      ->entityCondition('bundle', $right->bundle);
  }
  $result = $query
    ->execute();
  if (isset($result[$entity_type])) {
    $result[$entity_type] = entity_load($entity_type, array_keys($result[$entity_type]));
    foreach ($result[$entity_type] as $id => $entity) {
      $result[$entity_type][$id] = new EntityDrupalWrapper($entity_type, $entity);
    }
    return $result[$entity_type];
  }
  else {
    return array();
  }
}