You are here

function callback_my_module_mapper_unique in Feeds 7.2

Looks for an existing entity and returns an entity ID if found.

Callback for hook_feeds_processor_targets().

This callback is specified on the 'unique_callbacks' key of the target definition.

Parameters

FeedsSource $source: The Feed source.

string $entity_type: Entity type for the entity to be processed.

string $bundle: Bundle name for the entity to be processed.

string $target: A string identifying the unique target on the entity.

array $values: The unique values to be checked.

Return value

int|null The existing entity id, or NULL if no existing entity is found.

See also

hook_feeds_processor_targets()

FeedsProcessor::existingEntityId()

Related topics

1 string reference to 'callback_my_module_mapper_unique'
hook_feeds_processor_targets in ./feeds.api.php
Adds mapping targets for processors.

File

./feeds.api.php, line 566
Documentation of Feeds hooks.

Code

function callback_my_module_mapper_unique(FeedsSource $source, $entity_type, $bundle, $target, array $values) {
  list($field_name, $column) = explode(':', $target . ':value');

  // Example for if the target is a field.
  $query = new EntityFieldQuery();
  $result = $query
    ->entityCondition('entity_type', $entity_type)
    ->entityCondition('bundle', $bundle)
    ->fieldCondition($field_name, $column, $values)
    ->execute();
  if (!empty($result[$entity_type])) {
    return key($result[$entity_type]);
  }
}