You are here

function farm_inventory_form_farm_asset_form_alter in farmOS 7

Implements hook_form_FORM_ID_alter().

File

modules/farm/farm_inventory/farm_inventory.module, line 257

Code

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

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

  // If inventory is not enabled for this asset, bail.
  if (!farm_inventory_enabled($asset)) {
    return;
  }

  // Get the asset's current inventory.
  $inventory = farm_inventory($asset);

  // Add a field for setting the asset's current inventory.
  $form['inventory'] = array(
    '#type' => 'fieldset',
    '#title' => t('Inventory'),
    '#description' => t('Set the current inventory level for this asset. An observation log will be created automatically that adjusts the inventory level to match this value.'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#weight' => 100,
  );
  $form['inventory']['inventory'] = array(
    '#type' => 'textfield',
    '#title' => t('Current inventory'),
    '#default_value' => $inventory,
  );
  $form['actions']['submit']['#submit'][] = 'farm_inventory_asset_form_submit';
  $form['#group_children']['inventory'] = 'group_farm_general';
}