You are here

function farm_plan_type_form in farmOS 7

Generates the farm plan type editing form.

Parameters

array $form: The form array.

array $form_state: The form state array.

string $farm_plan_type: The farm plan type.

string $op: The operation being performed.

Return value

array Returns a form array.

File

modules/farm/farm_plan/farm_plan.admin.inc, line 23
Farm plan admin pages.

Code

function farm_plan_type_form(array $form, array &$form_state, $farm_plan_type, $op = 'edit') {
  if ($op == 'clone') {
    $farm_plan_type->label .= ' (cloned)';
    $farm_plan_type->type = '';
  }
  $form['label'] = array(
    '#title' => t('Label'),
    '#type' => 'textfield',
    '#default_value' => $farm_plan_type->label,
    '#description' => t('The human-readable name of this plan type.'),
    '#required' => TRUE,
    '#size' => 30,
  );

  // Machine-readable type name.
  $form['type'] = array(
    '#type' => 'machine_name',
    '#default_value' => !empty($farm_plan_type->type) ? $farm_plan_type->type : '',
    '#maxlength' => 32,
    '#disabled' => $farm_plan_type
      ->isLocked() && $op != 'clone',
    '#machine_name' => array(
      'exists' => 'farm_plan_types',
      'source' => array(
        'label',
      ),
    ),
    '#description' => t('A unique machine-readable name for this plan type. It must only contain lowercase letters, numbers, and underscores.'),
  );
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save plan type'),
    '#weight' => 40,
  );
  if (!$farm_plan_type
    ->isLocked() && $op != 'add' && $op != 'clone') {
    $form['actions']['delete'] = array(
      '#type' => 'submit',
      '#value' => t('Delete plan type'),
      '#weight' => 45,
      '#limit_validation_errors' => array(),
      '#submit' => array(
        'farm_plan_type_form_submit_delete',
      ),
    );
  }
  return $form;
}