Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.
- foreach ($mappings as $field => $mapping) {
- $field_instance = field_info_instance($type, $field, $bundle);
- if (!empty($field_instance)) {
- $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 two targets.
- $quantity_field_instance = field_info_instance($type, 'field_farm_quantity', $bundle);
- if (!empty($quantity_field_instance)) {
- $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,
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement