Skipping the whole entity item is easy by setting $entity->feeds_item->skip
to TRUE
.
However unsetting the selected fields could be more tricky. The workaround is to unset these fields in hook_feeds_presave
, however some more complex fields may not like to be unset and can generate some unpredictable errors (e.g. field collection).
So another approach is to load the old node and override the new values with the old. Here is some mixed example of unset some fields and override another:
/**
* Implements hook_feeds_presave().
*
* Invoked before a feed item is saved.
*/
function hook_feeds_presave(FeedsSource $source, $entity, $item) {
$config = $source->importer->getConfig();
$skip = &$entity->feeds_item->skip;
if ($entity->type == 'my_type') {
if ($status == FOO_SKIP_IT) {
// Don't update anything.
$skip = TRUE;
}
elseif (condition) {
$node = node_load($entity->nid); // Load the old values.
foreach ($entity as $key => $val) {
// Passing system fields and additional feed fields images and price.
if (in_array($key,
array(
'vid', 'uid', 'log', 'comment', 'promote', 'sticky', 'vuuid',
'nid', 'type', 'language', 'created', 'changed', 'tnid', 'translate',
'uuid', 'revision_timestamp', 'revision_uid', 'metatags', 'locations',
'location', 'name', 'picture', 'data', 'num_revisions', 'current_revision_id',
'is_current', 'is_pending', 'revision_moderation', 'date', 'revision', 'menu',
'feeds_item', 'guid', 'field_feed_status', 'field_collection', 'field_some_complex_field',
))) {
continue;
}
else {
// Unsetting unnecessary fields.
unset($entity->{$key});
}
}
// Override values with the old one.
$entity->field_collection = $node->field_collection;
$entity->field_some_complex_field = $node->field_some_complex_field;
}
else {
// Otherwise update all fields.
}
}
}
hook_node_presave()
which gives you the unchanged data and new data too.hook_feeds_presave()
is better.