You are here

function feeds_tamper_load_by_importer in Feeds Tamper 7

Same name and namespace in other branches
  1. 6 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

4 calls to feeds_tamper_load_by_importer()
feeds_tamper_features_pipe_feeds_importer_alter in ./feeds_tamper.module
Implements hook_features_pipe_COMPONENT_alter().
feeds_tamper_feeds_after_parse in ./feeds_tamper.module
Implements hook_feeds_after_parse().
feeds_tamper_ui_list_form in feeds_tamper_ui/feeds_tamper_ui.admin.inc
List of plugins for current importer.
_feeds_tamper_clone_tamper_plugins in feeds_tamper_ui/feeds_tamper_ui.module
Additional submit handler for feeds_build_create_form().

File

./feeds_tamper.inc, line 149
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);
  }
  ctools_include('export');
  $t = ctools_export_load_object('feeds_tamper', 'conditions', array(
    'importer' => $importer->id,
  ));
  $sources = feeds_tamper_get_unique_source_list($importer, FALSE);
  $plugins = feeds_tamper_get_plugins();
  $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) && isset($plugins[$i->plugin_id]) && function_exists($plugins[$i->plugin_id]['callback'])) {
      $instances[$i->source][] = $i;
    }
  }
  foreach ($instances as &$instance_list) {
    usort($instance_list, '_feeds_tamper_cmp');
  }

  // Sort the plugins by the order they appear on the mapping page.
  $return = array();
  foreach ($sources as $source) {
    if (isset($instances[$source])) {
      $return[$source] = $instances[$source];
    }
  }
  return $return;
}