The docs say:
* @return int
* The existing entity id, or 0 if not found.
but the implementation in the tests returns NULL when nothing is found:
/**
* Callback for unique_callbacks for test_target mapper.
*
* @see feeds_tests_feeds_processor_targets_alter()
*/
function feeds_tests_mapper_unique(FeedsSource $source, $entity_type, $bundle, $target, array $values) {
$query = new EntityFieldQuery();
$result = $query
->entityCondition('entity_type', $entity_type)
->entityCondition('bundle', $bundle)
->fieldCondition('field_alpha', 'value', $values)
->execute();
if (!empty($result[$entity_type])) {
return key($result[$entity_type]);
}
}
I would suggest the documentation is amended. It's better DX to return nothing when nothing is found than have to explicitly return a value.
Comments
Comment #1
megachrizYou are right. The "unique" callback doesn't have to return
0if the entity is not found. ReturningNULLor no value is good as well. I think these docs were confused withFeedsProcessor::existingEntityId(), which does return0if no existing entity is found.Comment #2
joachim commentedThanks for filling in the info!
Here's a patch.
Comment #3
megachrizIn an earlier patch from #661606: Support unique targets in mappers (which added the unique callback example) (patch at #175), the second part of the @return doc was as such:
Or NULL if no existing entity is found.But I think your version is good as well.
Comment #5
twistor commentedThanks. Added suggestion from #3.