3
0
Fork 0
mirror of https://github.com/farmOS/farmOS.git synced 2024-02-23 11:37:38 +01:00

Ensure that the farm asset(s) field is autofilled on any log type.

This commit is contained in:
Michael Stenta 2015-01-03 15:43:57 -05:00
parent 6138a0fa65
commit fbee2c550b

View file

@ -141,13 +141,31 @@ function farm_log_farm_area_links($id) {
*/
function farm_log_form_alter(&$form, &$form_state, $form_id) {
// If this is a log form with an asset(s) reference field.
if ($form_id == 'log_form' && (!empty($form['field_farm_asset']) || !empty($form['field_farm_assets']))) {
// First choice is farm_asset, second is farm_assets.
$field_name = (!empty($form['field_farm_asset'])) ? 'field_farm_asset' : 'field_farm_asset';
// Alter the form using our helper function.
// ($asset is used below to for movement logs.)
$asset = farm_log_form_prepopulate_asset($form, 'field_farm_asset');
}
// If this is a log form with an area(s) reference field...
if ($form_id == 'log_form' && (!empty($form['field_farm_area']) || !empty($form['field_farm_areas']))) {
// First choice is farm_area, second is farm_areas.
$field_name = (!empty($form['field_farm_area'])) ? 'field_farm_area' : 'field_farm_areas';
// Alter the form with the farm_log helper function.
farm_log_form_prepopulate_area($form, $field_name);
}
// If this is the farm_movement log form...
if ($form_id == 'log_form' && $form['#bundle'] == 'farm_movement') {
// Alter the form using our helper function.
$asset = farm_log_form_prepopulate_asset($form, 'field_farm_asset');
// If no asset was returned, don't continue.
// If no asset was found above, don't continue.
if (empty($asset)) {
return;
}
@ -162,16 +180,6 @@ function farm_log_form_alter(&$form, &$form_state, $form_id) {
}
}
}
// If this is a log form with an area(s) reference field...
if ($form_id == 'log_form' && (!empty($form['field_farm_area']) || !empty($form['field_farm_areas']))) {
// First choice is farm_area, second is farm_areas.
$field_name = (!empty($form['field_farm_area'])) ? 'field_farm_area' : 'field_farm_areas';
// Alter the form with the farm_log helper function.
farm_log_form_prepopulate_area($form, $field_name);
}
}
/**