importer->id, FALSE); // Don't go through all of the nonsense if we don't have anything to do. if (empty($importer_instances)) { return; } $csv = FALSE; if (get_class($source->importer->parser) == 'FeedsCSVParser') { $csv = TRUE; } // Look for any "Blank source" mappings as those will be treated specially. $mappings = $source->importer->processor->config['mappings']; $blank_mappings = array(); foreach ($importer_instances as $element_key => $instance) { if (strpos($element_key, 'Blank source ') === 0) { $blank_mappings[] = $element_key; } // Special case for FeedsCSVParser. elseif ($csv) { unset($importer_instances[$element_key]); $importer_instances[drupal_strtolower($element_key)] = $instance; } } $plugins = feeds_tamper_get_plugins(); foreach ($result->items as $item_key => &$item) { // Add the blank sources to the item. foreach ($blank_mappings as $blank) { $item[$blank] = ''; } foreach ($importer_instances as $element_key => $instances) { if (isset($item[$element_key])) { foreach ($instances as $instance) { $plugin = $plugins[$instance->plugin_id]; $is_array = is_array($item[$element_key]); if ($is_array && $plugin['multi'] == 'loop') { foreach ($item[$element_key] as &$i) { $plugin['callback']($result, $item_key, $element_key, $i, $instance->settings); } } elseif ($is_array && $plugin['multi'] == 'direct') { $plugin['callback']($result, $item_key, $element_key, $item[$element_key], $instance->settings); } elseif (!$is_array && $plugin['single'] != 'skip') { $plugin['callback']($result, $item_key, $element_key, $item[$element_key], $instance->settings); } } } } } } /** * Implements hook_feeds_parser_sources_alter(). */ function feeds_tamper_feeds_parser_sources_alter(&$sources, $content_type) { $sources['Blank source 1'] = array( 'description' => t("A source provided by Feeds Tamper with no value of it's own."), ); } /** * Implements hook_feeds_processor_targets_alter(). */ function feeds_tamper_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name) { $targets['Temporary target 1'] = array( 'description' => t('A field that stores the source data temporarily so that it can be used with the Feeds Tamper rewrite plugin.'), ); } /** * Core hooks. */ /** * Implements hook_permission(). */ function feeds_tamper_permission() { $perms = array( 'administer feeds_tamper' => array( 'title' => t('Administer Feeds Tamper'), 'description' => t('Create, edit and delete plugins for any importer.'), ), ); foreach (feeds_importer_load_all() as $importer) { $name = array('%name' => $importer->config['name']); $perms['tamper ' . $importer->id] = array( 'title' => t('Tamper %name feeds', $name), 'description' => t('Create, edit and delete plugins for %name feeds.', $name), ); } return $perms; } /** * Implements hook_ctools_plugin_type(). */ function feeds_tamper_ctools_plugin_type() { return array( 'plugins' => array( 'use hooks' => FALSE, 'defaults' => array( 'validate' => FALSE, 'multi' => FALSE, 'category' => 'Other', 'single' => FALSE, 'default description' => '', 'defaults' => array(), ), ), ); }