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

anchovie91471’s picture

This 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.

$importconfig = $source->importer()->getConfig();
$importname = $importconfig['name'];
vinmassaro’s picture

Component: Feeds Import » Code
Issue summary: View changes
Status: Active » Fixed

I ran into this today also and it turns out you can use $source->id inside hook_feeds_after_parse() to get the importer ID.

megachriz’s picture

Category: Feature request » Support request

Yes, and $source->feed_nid to get the ID of the feed node (in case the importer is attached to a content type).

megachriz’s picture

Importer object has id attribute that you need to check, but it is protected.

All properties of FeedsSource (and FeedsImporter, and any Feeds plugin class) are publicly readable, due to FeedsConfigurable implementing the magic method __get(). This is nowadays documented in the docblock above the FeedsConfigurable class (see the last few lines):

/**
 * Base class for configurable classes. Captures configuration handling, form
 * handling and distinguishes between in-memory configuration and persistent
 * configuration.
 *
 * Due to the magic method __get(), protected properties from this class and
 * from classes that extend this class will be publicly readable (but not
 * writeable).
 */
abstract class FeedsConfigurable {

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.