function field_validation_feeds_existing_entity_id in Field Validation 7.2
Callback for Feeds processor unique entity ID.
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 The existing entity id, or 0 if not found.
See also
field_validation_feeds_processor_targets_alter()
FeedsProcessor::existingEntityId()
1 string reference to 'field_validation_feeds_existing_entity_id'
File
- ./
field_validation.feeds.inc, line 44 - Integration with feeds to support unique targets in mappers.
Code
function field_validation_feeds_existing_entity_id(FeedsSource $source, $entity_type, $bundle, $target, array $values) {
module_load_include('inc', 'ctools', 'includes/export');
$unique_rules = ctools_export_load_object('field_validation_rule', 'conditions', array(
'entity_type' => $entity_type,
'bundle' => $bundle,
'field_name' => $target,
'validator' => 'field_validation_unique_validator',
));
$unique_rule = reset($unique_rules);
if (!empty($unique_rule)) {
// Get unique entity ID from unique field value. Note that we are not using
// field_validation_unique_validator::validate() because we don't want to
// fire set_error().
$query = new EntityFieldQuery();
$result = $query
->entityCondition('entity_type', $entity_type)
->entityCondition('bundle', $bundle)
->fieldCondition($target, $unique_rule->col, $values)
->addMetaData('account', user_load(1))
->execute();
if (isset($result[$entity_type])) {
return key($result[$entity_type]);
}
}
}