Create your own plugins

Last updated on
30 April 2025

Adding a new plugin is easy.

Simply add the following to your module file where plugins is the directory you want to store your plugins in.

<?php
/**
 * Implements hook_ctools_plugin_directory().
 */
function MODULE_ctools_plugin_directory($owner, $plugin_type){
  if ($owner == 'feeds_tamper' && $plugin_type == 'plugins') {
    return 'plugins';
  }
}
?>

Then, add a file to the plugins directory named my_plugin.inc.

<?php

/**
 * @file
 * Do super awesome thing.
 */

$plugin = array(
  'form' => 'MODULE_MY_PLUGIN_form',
  // Optional validation callback.
  'validate' => 'MODULE_MY_PLUGIN_validate',
  'callback' => 'MODULE_MY_PLUGIN_callback',
  'name' => 'My plugin',
  'multi' => 'loop',
  'category' => 'Other',
);

function MODULE_MY_PLUGIN_form($importer, $element_key, $settings) {
  $form = array();
  $form['help']['#value'] = t('My plugin can do awesome things.');
  //
  // Other formy stuff here.
  //
  return $form;
}

function MODULE_MY_PLUGIN_validate(&$settings) {
  // Validate $settings.
}

function MODULE_MY_PLUGIN_callback($feeds_parser_result, $item_key, $element_key, &$field, $settings, $feeds_source) {
  $field = crazy_modification($field);
}
?>

$plugin keys

  • 'multi' => can be either 'direct' or 'loop'. This specifies how to handle multiple valued fields. 'direct' will pass the whole array into the callback, whereas 'loop' will loop over the data, passing each value individually.
  • 'single' => 'skip' can be set if your plugin only wants to handle multiple-valued fields directly.

Validate

The validate callback is optional and can be used to set form errors on invalid input. There is, however, a more important task which the validate callback can be used for. It can be used to pre-compute values for the callback so that the callback has to do as little work as possible. See keyword_filter.inc for an example of this.

Callback

The full Feeds item can be accessed through $feeds_parser_result->items[$item_key]. With $feeds_parser_result->items[$item_key][$element_key] being the value of $field. This is provided to allow modifying/ removing the Feeds item as a whole. See keyword_filter.inc for an example.

The Feeds source ($feeds_source) can be used to access useful information, such as mapping settings, the raw feed, importer properties, etc.

Help improve this page

Page status: Not set

You can: