function farm_movement_asset_location_submit in farmOS 7
Submit handler for processing the asset location field.
Parameters
array $form: The form array.
array $form_state: The form state array.
1 string reference to 'farm_movement_asset_location_submit'
- farm_movement_form_farm_asset_form_alter in modules/
farm/ farm_movement/ farm_movement.location.inc - Implements hook_form_FORM_ID_alter().
File
- modules/
farm/ farm_movement/ farm_movement.location.inc, line 161 - Code for managing the location of assets with movement logs.
Code
function farm_movement_asset_location_submit(array $form, array &$form_state) {
// Only proceed if current location field has a value.
if (empty($form_state['values']['location']['areas'])) {
return;
}
// Only proceed if the value is not the default value.
if ($form_state['values']['location']['areas'] == $form['location']['areas']['#default_value']) {
return;
}
// If an asset doesn't exist, bail.
if (empty($form_state['values']['farm_asset'])) {
return;
}
// Grab the asset.
$asset = $form_state['values']['farm_asset'];
// Load the areas.
$areas = farm_term_parse_names($form_state['values']['location']['areas'], 'farm_areas', TRUE);
// Create an observation log to record the movement.
farm_movement_create($asset, $areas, REQUEST_TIME);
}