Trim whitespace from CSV fields: Asset names, Parent names, Areas, Categories, Crop/variety, Nicknames, Material.

This commit is contained in:
Michael Stenta 2019-10-08 16:53:34 -04:00
parent 148eda32b0
commit d47db78086
5 changed files with 36 additions and 8 deletions

View File

@ -189,7 +189,9 @@ function farm_crop_feeds_tamper_default_alter(&$feeds_tampers) {
$feeds_tamper = farm_import_feeds_tamper_plugin('farm_asset', 'animal', 'Crop/variety', 'required');
$feeds_tampers[$feeds_tamper->id] = $feeds_tamper;
// Explode crop/variety so it supports multiple values.
// Explode crop/variety so it supports multiple values, and trim whitespace.
$feeds_tamper = farm_import_feeds_tamper_plugin('farm_asset', 'planting', 'Crop/variety', 'explode');
$feeds_tampers[$feeds_tamper->id] = $feeds_tamper;
$feeds_tamper = farm_import_feeds_tamper_plugin('farm_asset', 'planting', 'Crop/variety', 'trim');
$feeds_tampers[$feeds_tamper->id] = $feeds_tamper;
}

View File

@ -25,12 +25,14 @@ function farm_import_feeds_tamper_default() {
$export[$feeds_tamper->id] = $feeds_tamper;
// If a parent asset field exists, explode "Parent IDs" and "Parent names"
// into arrays of IDs and names.
// into arrays of IDs and names. Trim whitespace from parent names.
if (!empty(field_info_instance('farm_asset', 'field_farm_parent', $bundle))) {
$feeds_tamper = farm_import_feeds_tamper_plugin('farm_asset', $bundle, 'Parent IDs', 'explode');
$export[$feeds_tamper->id] = $feeds_tamper;
$feeds_tamper = farm_import_feeds_tamper_plugin('farm_asset', $bundle, 'Parent names', 'explode');
$export[$feeds_tamper->id] = $feeds_tamper;
$feeds_tamper = farm_import_feeds_tamper_plugin('farm_asset', $bundle, 'Parent names', 'trim');
$export[$feeds_tamper->id] = $feeds_tamper;
}
}
@ -54,25 +56,33 @@ function farm_import_feeds_tamper_default() {
$export[$feeds_tamper->id] = $feeds_tamper;
// If an asset reference field exists, explode the "Asset IDs" and "Asset
// names" targets into arrays of IDs and names.
// names" targets into arrays of IDs and names. Trim whitespace from asset
// names.
if (!empty(field_info_instance('log', 'field_farm_asset', $bundle))) {
$feeds_tamper = farm_import_feeds_tamper_plugin('log', $bundle, 'Asset IDs', 'explode');
$export[$feeds_tamper->id] = $feeds_tamper;
$feeds_tamper = farm_import_feeds_tamper_plugin('log', $bundle, 'Asset names', 'explode');
$export[$feeds_tamper->id] = $feeds_tamper;
$feeds_tamper = farm_import_feeds_tamper_plugin('log', $bundle, 'Asset names', 'trim');
$export[$feeds_tamper->id] = $feeds_tamper;
}
// If an "Areas" field exists, explode it into an array of area names.
// If an "Areas" field exists, explode it into an array of area names and
// trim whitespace.
if (!empty(field_info_instance('log', 'field_farm_area', $bundle))) {
$feeds_tamper = farm_import_feeds_tamper_plugin('log', $bundle, 'Areas', 'explode');
$export[$feeds_tamper->id] = $feeds_tamper;
$feeds_tamper = farm_import_feeds_tamper_plugin('log', $bundle, 'Areas', 'trim');
$export[$feeds_tamper->id] = $feeds_tamper;
}
// If a "Categories" field exists, explode it into an array of category
// names.
// names and trim whitespace.
if (!empty(field_info_instance('log', 'field_farm_log_category', $bundle))) {
$feeds_tamper = farm_import_feeds_tamper_plugin('log', $bundle, 'Categories', 'explode');
$export[$feeds_tamper->id] = $feeds_tamper;
$feeds_tamper = farm_import_feeds_tamper_plugin('log', $bundle, 'Categories', 'trim');
$export[$feeds_tamper->id] = $feeds_tamper;
}
}

View File

@ -185,6 +185,15 @@ function farm_import_feeds_tamper_plugin($entity_type, $bundle, $source, $plugin
);
break;
// Trim whitespace.
case 'trim':
$description = 'Trim';
$settings = array(
'mask' => '',
'side' => 'trim',
);
break;
// Empty defaults.
default:
$description = '';

View File

@ -268,15 +268,20 @@ function farm_livestock_feeds_tamper_default_alter(&$feeds_tampers) {
$feeds_tamper = farm_import_feeds_tamper_plugin('farm_asset', 'animal', 'Date of birth', 'strtotime');
$feeds_tampers[$feeds_tamper->id] = $feeds_tamper;
// Explode nicknames to allow multiple values.
// Explode nicknames to allow multiple values, and trim whitespace.
$feeds_tamper = farm_import_feeds_tamper_plugin('farm_asset', 'animal', 'Nicknames', 'explode');
$feeds_tampers[$feeds_tamper->id] = $feeds_tamper;
$feeds_tamper = farm_import_feeds_tamper_plugin('farm_asset', 'animal', 'Nicknames', 'trim');
$feeds_tampers[$feeds_tamper->id] = $feeds_tamper;
// Explode birth children IDs and names to allow multiple values.
// Explode birth children IDs and names to allow multiple values, and trim
// whitespace from names.
$feeds_tamper = farm_import_feeds_tamper_plugin('log', 'farm_birth', 'Children IDs', 'explode');
$feeds_tampers[$feeds_tamper->id] = $feeds_tamper;
$feeds_tamper = farm_import_feeds_tamper_plugin('log', 'farm_birth', 'Children names', 'explode');
$feeds_tampers[$feeds_tamper->id] = $feeds_tamper;
$feeds_tamper = farm_import_feeds_tamper_plugin('log', 'farm_birth', 'Children names', 'trim');
$feeds_tampers[$feeds_tamper->id] = $feeds_tamper;
}
/**

View File

@ -97,7 +97,9 @@ function farm_log_input_feeds_tamper_default_alter(&$feeds_tampers) {
$feeds_tamper = farm_import_feeds_tamper_plugin('log', 'farm_input', 'Date purchased', 'strtotime');
$feeds_tampers[$feeds_tamper->id] = $feeds_tamper;
// Explode the "Material" target into an array.
// Explode the "Material" target into an array and trim whitespace.
$feeds_tamper = farm_import_feeds_tamper_plugin('log', 'farm_input', 'Material', 'explode');
$feeds_tampers[$feeds_tamper->id] = $feeds_tamper;
$feeds_tamper = farm_import_feeds_tamper_plugin('log', 'farm_input', 'Material', 'trim');
$feeds_tampers[$feeds_tamper->id] = $feeds_tamper;
}