I have a module that is using hook_feeds_presave. I want to only run specific parts of this function based on the feeds importer that is running. How can I check for the ID of the feed? These are standalone feeds and don't use node forms.
3 Answers
Try printing $source->id
( even if $source
seems empty ). This should return the machine name.
It's what I always use.
-
-
The "even if $source seems empty" part doesn't make sense to me, what do you mean? Commented Dec 1, 2012 at 13:15
-
When I print the variable $source ( using dpm() function from Devel ) in hook_feeds_presave(), I get '(Object) FeedsSource', but I cannot explore it further. I can't click on it to see what else is in there. However, by looking through the code of Feeds, I noticed that $source has a property 'id', so I tried printing that. And it works, I can see the machine name of my feed importer when I print $source->id in hook_feeds_presave()– VoddeCommented Dec 3, 2012 at 13:16
Not tested but I think you can print_r and see yourself. function MYMODULE_feeds_presave($source, &$node){ drupal_set_message(print_r($source,1)); }
function MYMODULE_feeds_presave(FeedsSource $source, $entity, $item) {
if($source->importer->id=='FEED_ID'){
# code...
}
}
$source->importer->id provides the ID of the feed