In a case if you want to run your code in hook_feeds_after_parse only for import with some particular id, it is a bit tricky to get the id of running import.
In hook_feeds_after_parse you have FeedsSource object as an argument, and you should use FeedsSource::importer() to get Importer object first. Importer object has id attribute that you need to check, but it is protected. You may use Importer::getConfig() to get importer properties, but it returns only the human name of the importer.
So actually I am not sure is there is some way to get the importer ID by FeedsSource object in hook_feeds_after_parse
I suggest to:
* add getId() method to Importer class
* add getImporterId() method to FeedsSource class
* add $importer_id argument to hook_feeds_after_parse and all other alter hooks listed in feeds.api.php
If Implementing of these is a good Idea and can be added to the feeds_import module I can provide a patch for listed changes.
Comments
Comment #1
anchovie91471 commentedThis post is rather old, but in case anyone needs to find out how to do this. Within my hook_feeds_after_parse call, I did this. Perfectly do-able within the function.
Comment #2
vinmassaro commentedI ran into this today also and it turns out you can use
$source->idinsidehook_feeds_after_parse()to get the importer ID.Comment #3
megachrizYes, and
$source->feed_nidto get the ID of the feed node (in case the importer is attached to a content type).Comment #4
megachrizAll properties of FeedsSource (and FeedsImporter, and any Feeds plugin class) are publicly readable, due to
FeedsConfigurableimplementing the magic method__get(). This is nowadays documented in the docblock above theFeedsConfigurableclass (see the last few lines):