You are here

function farm_livestock_feeds_tamper_default_alter in farmOS 7

Implements hook_feeds_tamper_default_alter().

File

modules/farm/farm_livestock/farm_livestock.module, line 240

Code

function farm_livestock_feeds_tamper_default_alter(&$feeds_tampers) {

  // If farm_import is not installed, bail.
  if (!module_exists('farm_import')) {
    return;
  }

  // Make species/breed required.
  $feeds_tamper = farm_import_feeds_tamper_plugin('farm_asset', 'animal', 'Species/breed', 'required');
  $feeds_tampers[$feeds_tamper->id] = $feeds_tamper;

  // Convert "male" to "M".
  $feeds_tamper = farm_import_feeds_tamper_plugin('farm_asset', 'animal', 'Sex', 'find_replace', array(
    'find' => t('male'),
    'replace' => 'M',
  ));
  $feeds_tamper->id .= '-male';
  $feeds_tamper->weight = 1;
  $feeds_tampers[$feeds_tamper->id] = $feeds_tamper;

  // Convert "female" to "F".
  $feeds_tamper = farm_import_feeds_tamper_plugin('farm_asset', 'animal', 'Sex', 'find_replace', array(
    'find' => t('female'),
    'replace' => 'F',
  ));
  $feeds_tamper->id .= '-female';
  $feeds_tamper->weight = 2;
  $feeds_tampers[$feeds_tamper->id] = $feeds_tamper;

  // Convert castrated to boolean.
  $feeds_tamper = farm_import_feeds_tamper_plugin('farm_asset', 'animal', 'Castrated', 'boolean_default_false');
  $feeds_tampers[$feeds_tamper->id] = $feeds_tamper;

  // Convert date of birth to a Unix timestamp.
  $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, 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, 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;
}