You are here

function feeds_tamper_efq_finder_callback in Feeds Tamper 7

Sets an entity id based on the value of a field.

1 string reference to 'feeds_tamper_efq_finder_callback'
efq_finder.inc in plugins/efq_finder.inc

File

plugins/efq_finder.inc, line 166

Code

function feeds_tamper_efq_finder_callback($result, $item_key, $element_key, &$field, array $settings) {
  $query = new EntityFieldQuery();
  $query
    ->entityCondition('entity_type', $settings['entity_type']);
  if ($settings['bundle']) {
    $query
      ->entityCondition('bundle', $settings['bundle']);
  }
  if ($settings['property']) {
    $query
      ->propertyCondition($settings['field'], $field);
  }
  else {
    $query
      ->fieldCondition($settings['field'], $settings['column'], $field);
  }
  $query
    ->range(0, 1);
  $query_result = $query
    ->execute();

  // @todo: Implement choice of behavior when multiple entities are found.
  // Currently we only use the first.
  if (!empty($query_result)) {
    $result = reset($query_result);
    $field = key($result);
  }
  else {

    // We didn't find a value, remove the item.
    // @todo Fallback.
    unset($result->items[$item_key][$element_key]);
  }
}