function farm_plan_form in farmOS 7
Plan form.
Parameters
array $form: The form array.
array $form_state: The form state array.
FarmPlan $farm_plan: The farm plan entity.
Return value
array Returns a form array.
2 string references to 'farm_plan_form'
- farm_plan_add in modules/
farm/ farm_plan/ farm_plan.pages.inc - Add new plan page callback.
- farm_plan_menu in modules/
farm/ farm_plan/ farm_plan.module - Implements hook_menu().
File
- modules/
farm/ farm_plan/ farm_plan.pages.inc, line 81 - Farm plan pages.
Code
function farm_plan_form(array $form, array &$form_state, FarmPlan $farm_plan) {
$form['farm_plan'] = array(
'#type' => 'value',
'#value' => $farm_plan,
);
// Load the plan type.
$farm_plan_type = farm_plan_type_load($farm_plan->type);
// Plan name.
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
'#description' => t('Give this %type a name.', array(
'%type' => $farm_plan_type->label,
)),
'#default_value' => $farm_plan->name,
'#required' => TRUE,
'#weight' => -100,
);
// Additional settings (vertical tabs at the bottom of the form).
$form['additional_settings'] = array(
'#type' => 'vertical_tabs',
'#weight' => 99,
);
// Plan active/inactive (new plans are active by default).
if (empty($farm_plan->id)) {
$farm_plan->active = TRUE;
}
$form['plan_status'] = array(
'#type' => 'fieldset',
'#title' => t('Plan status'),
'#description' => t('Mark this plan as active/inactive. Inactive plans will not show in most lists, but will be visible in archives.'),
'#collapsible' => TRUE,
'#group' => 'additional_settings',
);
$form['plan_status']['active'] = array(
'#type' => 'checkbox',
'#title' => t('Active'),
'#default_value' => $farm_plan->active,
);
// Plan user id.
$form['uid'] = array(
'#type' => 'value',
'#value' => $farm_plan->uid,
);
field_attach_form('farm_plan', $farm_plan, $form, $form_state);
$submit = array();
if (!empty($form['#submit'])) {
$submit += $form['#submit'];
}
$form['actions'] = array(
'#weight' => 100,
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#submit' => $submit + array(
'farm_plan_form_submit',
),
);
// Show Delete button if allowed.
$farm_plan_id = entity_id('farm_plan', $farm_plan);
if (!empty($farm_plan_id) && farm_plan_access('delete', $farm_plan)) {
// Get the destination query parameter. If it is the current path, change
// to <front> (because the current path won't exist once the plan 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/plan/' . $farm_plan_id . '/delete', array(
'query' => $destination,
)),
);
}
return $form;
}