Skip to main content
knackforge blog knowledge base

Create feed importer with custom module

Drupal family members would be well aware about the power of Feeds module. More than many times, thereof has served us in creating new contents with less work and time. Recently I looked the feeds module from a unseen angle, "How to create feeds importer from my custom module?".  To make my requirement clear please visit Quiz Questions Import module's page and if possible use this to get a clear picture about what this blog can do for you.

The Quiz Questions Import module on enabling creates a list of feeds importer, and these importers can be used to import content in CSV format. I don't want to get too deep into the concept of creating such a module, but will limit to the exact API needed to make this work.

  1. Create a new custom feed importer in Structure -> Feeds importer
  2. Select the Fetcher, Parser and Preprocessor as per your requirement
  3. Once done, export this feeds configuration (Can be found in the export tab)
  4. Paste this code in your custom module

Many who have gone though the above steps would have failed to attain success, In simple terms on enabling this custom module you would not find any importer being created. To accomplish all we need is hook_ctools_plugin_api().

  1. /**
  2.  * Implements hook_ctools_plugin_api()
  3.  */
  4. function qq_import_ctools_plugin_api() {
  5.   $args = func_get_args();
  6.   $module = array_shift($args);
  7.   $api = array_shift($args);
  8.   if ($module == "feeds" && $api == "feeds_importer_default") {
  9.     return array("version" => 1);
  10.   }
  11. }

The above piece of code has been taken from Quiz Question Import module, replace qq_import with your module's name. Apart from that no other real change is needed. Now disable and if needed uninstall your custom module and enable it again. Voila feed importer in /import page.