You are here

function farm_livestock_milk_form_submit in farmOS 7

Submit function for milk quick form.

File

modules/farm/farm_livestock/farm_livestock.farm_quick.milk.inc, line 121
Farm livestock milk quick form.

Code

function farm_livestock_milk_form_submit($form, &$form_state) {

  // Remember what was entered for measure and units. This will be used as the
  // default the next time the form is loaded.
  variable_set('farm_livestock_milk_measure', $form_state['values']['measure']);
  variable_set('farm_livestock_milk_units', $form_state['values']['units']);

  // Get the asset and wrap it in an array.
  $asset = $form_state['storage']['asset'];
  $assets = array(
    $asset,
  );

  // The log type will be a harvest.
  $log_type = 'farm_harvest';

  // Set log name.
  $log_name = t('Milk') . ' ' . format_string('!asset: !qty !units', array(
    '!asset' => entity_label('farm_asset', $asset),
    '!qty' => $form_state['values']['quantity'],
    '!units' => $form_state['values']['units'],
  ));

  // Assemble an array of measurements.
  $measurements = array(
    array(
      'measure' => $form_state['values']['measure'],
      'value' => $form_state['values']['quantity'],
      'units' => $form_state['values']['units'],
      'label' => t('milk'),
    ),
  );

  // Create a new farm quantity log.
  $log = farm_quantity_log_create($log_type, $log_name, REQUEST_TIME, TRUE, $assets, $measurements);

  // Link the log to the quick form.
  if (function_exists('farm_quick_entity_link')) {
    farm_quick_entity_link('farm_livestock_milk_form', 'log', $log);
  }
}