You are here

function feeds_tamper_load_by_importer in Feeds Tamper 6

Same name and namespace in other branches
  1. 7 feeds_tamper.inc \feeds_tamper_load_by_importer()

Load plugin instances by importer id.

Parameters

string|FeedsImporter $importer: The importer id, or object to reference.

bool $disabled: (optional) If TRUE load disabled plugin instances. Defaults to FALSE.

Return value

array An associative array of plugin instances, keyed by source.

Related topics

2 calls to feeds_tamper_load_by_importer()
feeds_tamper_feeds_after_parse in ./feeds_tamper.module
Implementation of hook_feeds_after_parse().
feeds_tamper_ui_list_form in feeds_tamper_ui/feeds_tamper_ui.admin.inc
@file Forms and their accompanying validation and submit functions for Feeds Tamper UI.

File

./feeds_tamper.inc, line 117
Version agnostic parts of feeds_tamper.module.

Code

function feeds_tamper_load_by_importer($importer, $disabled = FALSE) {
  if (is_scalar($importer)) {
    $importer = feeds_importer($importer);
  }
  $mappings = $importer->processor->config['mappings'];
  $sources = array();
  foreach ($mappings as $mapping) {
    $sources[] = $mapping['source'];
  }
  ctools_include('export');
  $t = ctools_export_load_object('feeds_tamper', 'conditions', array(
    'importer' => $importer->id,
  ));

  // Sort into array, keyed by source.
  $instances = array();
  foreach ($t as $i) {

    // Add an empty settings array, if the plugin instance doesn't provide any settings itself.
    if (empty($i->settings)) {
      $i->settings = array();
    }

    // Filter disabled and only pull plugins that actually have a corresponding
    // source since we don't delete them with a mapping.
    if (($disabled || empty($i->disabled)) && in_array($i->source, $sources)) {
      $instances[$i->source][] = $i;
    }
  }
  foreach ($instances as &$instance_list) {
    usort($instance_list, '_feeds_tamper_cmp');
  }
  return $instances;
}