Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.53 KB | None | 0 0
  1. function farm_import_add_importer_fields($type, $bundle, $importer) {
  2.  
  3.   // If the importer doesn't have a mapping array for some reason, bail.
  4.   if (empty($importer->config['processor']['config']['mappings'])) {
  5.     return;
  6.   }
  7.  
  8.   // Get field mappings, depending on the type.
  9.   switch ($type) {
  10.     case 'farm_asset':
  11.       $mappings = farm_import_asset_field_mappings();
  12.       break;
  13.     case 'log':
  14.       $mappings = farm_import_log_field_mappings();
  15.       break;
  16.     default:
  17.       $mappings = array();
  18.   }
  19.  
  20.   // Add fields, if they exist on the bundle.
  21.   foreach ($mappings as $field => $mapping) {
  22.     $field_instance = field_info_instance($type, $field, $bundle);
  23.     if (!empty($field_instance)) {
  24.       $importer->config['processor']['config']['mappings'][] = $mapping;
  25.     }
  26.   }
  27.  
  28.   // Add Quantity field, if it exists. This is a bit more complicated because
  29.   // it is a field collection, so there are two targets.
  30.   $quantity_field_instance = field_info_instance($type, 'field_farm_quantity', $bundle);
  31.   if (!empty($quantity_field_instance)) {
  32.     $importer->config['processor']['config']['mappings'][] = array(
  33.       'source' => 'Quantity value',
  34.       'target' => 'field_farm_quantity:field_farm_quantity_value',
  35.       'unique' => FALSE,
  36.       'language' => 'und',
  37.     );
  38.     $importer->config['processor']['config']['mappings'][] = array(
  39.       'source' => 'Quantity unit',
  40.       'target' => 'field_farm_quantity:field_farm_quantity_units',
  41.       'term_search' => '0',
  42.       'autocreate' => 1,
  43.     );
  44.   }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement