You are here

function farm_import_add_importer_fields in farmOS 7

Add common field mappings to importers.

Parameters

$type: The entity type.

$bundle: The asset bundle.

$importer: The importer configuration object that will be altered.

1 call to farm_import_add_importer_fields()
farm_import_feeds_importer_default in modules/farm/farm_import/farm_import.feeds_importer_default.inc
Implements hook_feeds_importer_default().

File

modules/farm/farm_import/farm_import.feeds_importer_default.inc, line 196
Feeds importers provided by the farm import module.

Code

function farm_import_add_importer_fields($type, $bundle, $importer) {

  // If the importer doesn't have a mapping array for some reason, bail.
  if (empty($importer->config['processor']['config']['mappings'])) {
    return;
  }

  // Get field mappings, depending on the type.
  switch ($type) {
    case 'farm_asset':
      $mappings = farm_import_asset_field_mappings();
      break;
    case 'log':
      $mappings = farm_import_log_field_mappings();
      break;
    default:
      $mappings = array();
  }

  // Add fields, if they exist on the bundle, or if they are "custom".
  foreach ($mappings as $field => $mapping) {
    if (!empty($mapping['real_field'])) {
      $field = $mapping['real_field'];
    }
    if (!empty($mapping['custom']) || !empty(field_info_instance($type, $field, $bundle))) {
      $importer->config['processor']['config']['mappings'][] = $mapping;
    }
  }

  // Add Quantity field, if it exists. This is a bit more complicated because
  // it is a field collection, so there are multiple targets.
  if (!empty(field_info_instance($type, 'field_farm_quantity', $bundle))) {
    $importer->config['processor']['config']['mappings'][] = array(
      'source' => 'Quantity measure',
      'target' => 'field_farm_quantity:field_farm_quantity_measure',
      'unique' => FALSE,
      'language' => 'und',
    );
    $importer->config['processor']['config']['mappings'][] = array(
      'source' => 'Quantity value',
      'target' => 'field_farm_quantity:field_farm_quantity_value',
      'unique' => FALSE,
      'language' => 'und',
    );
    $importer->config['processor']['config']['mappings'][] = array(
      'source' => 'Quantity unit',
      'target' => 'field_farm_quantity:field_farm_quantity_units',
      'term_search' => '0',
      'autocreate' => 1,
    );
    $importer->config['processor']['config']['mappings'][] = array(
      'source' => 'Quantity label',
      'target' => 'field_farm_quantity:field_farm_quantity_label',
      'unique' => FALSE,
      'language' => 'und',
    );
  }
}