You are here

function farm_asset_form in farmOS 7

Asset form.

Parameters

array $form: The form array.

array $form_state: The form state array.

FarmAsset $farm_asset: The farm asset entity.

Return value

array Returns a form array.

3 string references to 'farm_asset_form'
farm_asset_add in modules/farm/farm_asset/farm_asset.pages.inc
Add new asset page callback.
farm_asset_menu in modules/farm/farm_asset/farm_asset.module
Implements hook_menu().
farm_sensor_form_alter in modules/farm/farm_sensor/farm_sensor.module
Implements hook_form_alter().

File

modules/farm/farm_asset/farm_asset.pages.inc, line 81
Farm asset pages.

Code

function farm_asset_form(array $form, array &$form_state, FarmAsset $farm_asset) {
  $form['farm_asset'] = array(
    '#type' => 'value',
    '#value' => $farm_asset,
  );

  // Load the asset type.
  $farm_asset_type = farm_asset_type_load($farm_asset->type);

  // Asset name.
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#description' => t('Give this %type asset a name.', array(
      '%type' => $farm_asset_type->label,
    )),
    '#default_value' => $farm_asset->name,
    '#required' => TRUE,
    '#weight' => -100,
  );

  // Additional settings (vertical tabs at the bottom of the form).
  $form['additional_settings'] = array(
    '#type' => 'vertical_tabs',
    '#weight' => 99,
  );

  // Asset archived status.
  $archived_boolean = FALSE;
  $archived_date = '';
  if (!empty($farm_asset->archived)) {
    $archived_boolean = TRUE;
    $archived_date = ' (' . format_date($farm_asset->archived) . ')';
  }
  $form['asset_status'] = array(
    '#type' => 'fieldset',
    '#title' => t('Asset status'),
    '#description' => t('Archive this asset. Archived assets will not show in most lists, but will be visible in archives.'),
    '#collapsible' => TRUE,
    '#group' => 'additional_settings',
  );
  $form['asset_status']['archived_boolean'] = array(
    '#type' => 'checkbox',
    '#title' => t('Archived') . $archived_date,
    '#default_value' => $archived_boolean,
  );
  $form['asset_status']['archived'] = array(
    '#type' => 'value',
    '#value' => $farm_asset->archived,
  );

  // Asset user id.
  $form['uid'] = array(
    '#type' => 'value',
    '#value' => $farm_asset->uid,
  );
  field_attach_form('farm_asset', $farm_asset, $form, $form_state);
  $form['actions'] = array(
    '#weight' => 100,
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
    '#validate' => array(
      'farm_asset_form_validate',
    ),
    '#submit' => array(
      'farm_asset_form_submit',
    ),
  );

  // Show Delete button if allowed.
  $farm_asset_id = entity_id('farm_asset', $farm_asset);
  if (!empty($farm_asset_id) && farm_asset_access('delete', $farm_asset)) {

    // Get the destination query parameter. If it is the current path, change
    // to <front> (because the current path won't exist once the asset is
    // deleted).
    $destination = drupal_get_destination();
    if ($destination['destination'] == current_path()) {
      $destination['destination'] = '<front>';
    }
    $form['actions']['delete'] = array(
      '#type' => 'markup',
      '#markup' => l(t('Delete'), 'farm/asset/' . $farm_asset_id . '/delete', array(
        'query' => $destination,
      )),
    );
  }
  return $form;
}