Prepopulate the Movement log's asset reference field when a farm_asset query parameter is set.

This commit is contained in:
Michael Stenta 2014-11-13 15:53:13 -05:00
parent c021a45c52
commit 3fe9b1b2af
1 changed files with 23 additions and 0 deletions

View File

@ -5,3 +5,26 @@
*/
include_once 'farm_log.features.inc';
/**
* Implements hook_form_alter().
*/
function farm_log_form_alter(&$form, &$form_state, $form_id) {
// If this is the farm_movement log form...
if ($form_id == 'log_form' && $form['#bundle'] == 'farm_movement') {
// If the "farm_asset" query parameter is set...
$params = drupal_get_query_parameters();
if (!empty($params['farm_asset'])) {
// Verify that the farm_asset is valid.
$asset = farm_asset_load($params['farm_asset']);
if ($asset) {
// Prepopulate the movement's asset reference field.
$form['field_farm_asset'][LANGUAGE_NONE][0]['target_id']['#default_value'] = entity_label('farm_asset', $asset) . ' (' . $asset->id . ')';
}
}
}
}