You are here

function farm_livestock_weight_form_farm_asset_form_alter in farmOS 7

Implements hook_form_FORM_ID_alter().

File

modules/farm/farm_livestock/farm_livestock_weight/farm_livestock_weight.module, line 880
Farm livestock weight module.

Code

function farm_livestock_weight_form_farm_asset_form_alter(&$form, &$form_state, $form_id) {

  // Get the farm asset entity from the form.
  $asset = $form['farm_asset']['#value'];

  // If the asset is not an animal, bail.
  if ($asset->type != 'animal') {
    return;
  }

  // Get the animal's current weight.
  $weight = farm_livestock_weight($asset);

  // Add a field for setting the animal's current weight.
  $form['weight'] = array(
    '#type' => 'fieldset',
    '#title' => t('Weight'),
    '#description' => t('Set the current weight for this animal. If this record is used to represent multiple animals, enter their average weight. An observation log will be created automatically to record the weight.'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#weight' => 100,
    '#tree' => TRUE,
  );
  $form['weight']['value'] = array(
    '#type' => 'textfield',
    '#title' => t('Weight'),
    '#default_value' => !empty($weight['value']) ? $weight['value'] : '',
    '#element_validate' => array(
      'element_validate_number',
    ),
  );
  $form['weight']['units'] = array(
    '#type' => 'textfield',
    '#title' => t('Units'),
    '#autocomplete_path' => 'taxonomy/autocomplete/field_farm_quantity_units',
    '#default_value' => !empty($weight['units']) ? $weight['units'] : '',
  );
  $form['actions']['submit']['#validate'][] = 'farm_livestock_weight_asset_form_validate';
  $form['actions']['submit']['#submit'][] = 'farm_livestock_weight_asset_form_submit';
  $form['#group_children']['weight'] = 'group_farm_general';
}