From cd16fb7bf8da40ee3101d110aa5f867c1c21553f Mon Sep 17 00:00:00 2001 From: Michael Stenta Date: Wed, 5 Jul 2017 09:06:54 -0400 Subject: [PATCH] Add extra Feeds field mapping to plantings, animals, and equipment. --- modules/farm/farm_crop/farm_crop.module | 29 ++++++++ .../farm/farm_equipment/farm_equipment.module | 33 +++++++++ .../farm/farm_livestock/farm_livestock.module | 71 +++++++++++++++++++ 3 files changed, 133 insertions(+) diff --git a/modules/farm/farm_crop/farm_crop.module b/modules/farm/farm_crop/farm_crop.module index 8e4dd765..5fe9a5ae 100644 --- a/modules/farm/farm_crop/farm_crop.module +++ b/modules/farm/farm_crop/farm_crop.module @@ -221,3 +221,32 @@ function farm_crop_farm_log_categories() { // Provide an "Plantings" log category. return array('Plantings'); } + +/** + * Implements hook_feeds_importer_default_alter(). + */ +function farm_crop_feeds_importer_default_alter(&$importers) { + + // Add extra field mappings to plantings. + $name = 'farm_asset_planting'; + if (!empty($importers[$name])) { + $mappings = array( + array( + 'source' => 'Crop/variety', + 'target' => 'field_farm_crop', + 'term_search' => '0', + 'autocreate' => 1, + 'language' => 'und', + ), + array( + 'source' => 'Season', + 'target' => 'field_farm_season', + 'term_search' => '0', + 'autocreate' => 1, + 'language' => 'und', + ), + ); + $importer_mappings =& $importers[$name]->config['processor']['config']['mappings']; + $importer_mappings = array_merge($importer_mappings, $mappings); + } +} diff --git a/modules/farm/farm_equipment/farm_equipment.module b/modules/farm/farm_equipment/farm_equipment.module index 783f5c10..bc5143c3 100644 --- a/modules/farm/farm_equipment/farm_equipment.module +++ b/modules/farm/farm_equipment/farm_equipment.module @@ -38,3 +38,36 @@ function farm_equipment_farm_log_categories() { // Provide an "Equipment" log category. return array('Equipment'); } + +/** + * Implements hook_feeds_importer_default_alter(). + */ +function farm_equipment_feeds_importer_default_alter($importers) { + + // Add extra field mappings to equipment. + $name = 'farm_asset_equipment'; + if (!empty($importers[$name])) { + $mappings = array( + array( + 'source' => 'Manufacturer', + 'target' => 'field_farm_manufacturer', + 'unique' => FALSE, + 'language' => 'und', + ), + array( + 'source' => 'Model', + 'target' => 'field_farm_model', + 'unique' => FALSE, + 'language' => 'und', + ), + array( + 'source' => 'Serial number', + 'target' => 'field_farm_serial_number', + 'unique' => FALSE, + 'language' => 'und', + ), + ); + $importer_mappings =& $importers[$name]->config['processor']['config']['mappings']; + $importer_mappings = array_merge($importer_mappings, $mappings); + } +} diff --git a/modules/farm/farm_livestock/farm_livestock.module b/modules/farm/farm_livestock/farm_livestock.module index 08aa17e6..62b9fb95 100644 --- a/modules/farm/farm_livestock/farm_livestock.module +++ b/modules/farm/farm_livestock/farm_livestock.module @@ -67,3 +67,74 @@ function farm_livestock_farm_log_categories() { // Provide an "Animals" log category. return array('Animals'); } + +/** + * Implements hook_feeds_importer_default_alter(). + */ +function farm_livestock_feeds_importer_default_alter($importers) { + + // Add extra field mappings to animals. + $name = 'farm_asset_animal'; + if (!empty($importers[$name])) { + $mappings = array( + array( + 'source' => 'Nicknames', + 'target' => 'field_farm_animal_nicknames', + 'unique' => FALSE, + 'language' => 'und', + ), + array( + 'source' => 'Date of birth', + 'target' => 'field_farm_date:start', + 'unique' => FALSE, + 'language' => 'und', + ), + array( + 'source' => 'Species/breed', + 'target' => 'field_farm_animal_type', + 'term_search' => '0', + 'autocreate' => 1, + 'language' => 'und', + ), + array( + 'source' => 'Group', + 'target' => 'field_farm_animal_group', + 'term_search' => '0', + 'autocreate' => 1, + 'language' => 'und', + ), + array( + 'source' => 'Sex', + 'target' => 'field_farm_animal_sex', + 'unique' => FALSE, + 'language' => 'und', + ), + array( + 'source' => 'Castrated', + 'target' => 'field_farm_animal_castrated', + 'unique' => FALSE, + 'language' => 'und', + ), + array( + 'source' => 'Tag ID', + 'target' => 'field_farm_animal_tag:field_farm_animal_tag_id', + 'unique' => FALSE, + 'language' => 'und', + ), + array( + 'source' => 'Tag type', + 'target' => 'field_farm_animal_tag:field_farm_animal_tag_type', + 'unique' => FALSE, + 'language' => 'und', + ), + array( + 'source' => 'Tag location', + 'target' => 'field_farm_animal_tag:field_farm_animal_tag_location', + 'unique' => FALSE, + 'language' => 'und', + ), + ); + $importer_mappings =& $importers[$name]->config['processor']['config']['mappings']; + $importer_mappings = array_merge($importer_mappings, $mappings); + } +}