function farm_soil_compost_temperature_form in farmOS 7
Form for adding compost temperature logs.
2 string references to 'farm_soil_compost_temperature_form'
- farm_soil_compost_farm_quick_forms in modules/
farm/ farm_soil/ farm_soil_compost/ farm_soil_compost.farm_quick.inc - Implements hook_farm_quick_forms().
- farm_soil_compost_temperature_form_submit in modules/
farm/ farm_soil/ farm_soil_compost/ farm_soil_compost.farm_quick.inc - Submit function for compost temperature quick form.
File
- modules/
farm/ farm_soil/ farm_soil_compost/ farm_soil_compost.farm_quick.inc, line 24 - Farm soil compost quick forms.
Code
function farm_soil_compost_temperature_form($form, &$form_state) {
// Wrapper fieldset.
$form['temperature'] = array(
'#type' => 'fieldset',
'#title' => t('Record compost temperature'),
'#description' => t('Use this form to record the temperature of a compost pile. An observation log will be created with standard details filled in.'),
);
// Load active compost assets.
$asset_options = array();
$result = db_query("SELECT a.id FROM {farm_asset} a WHERE a.type = 'compost' AND a.archived = 0");
foreach ($result as $row) {
if (!empty($row->id)) {
// Load the asset.
$asset = farm_asset_load($row->id);
// If the asset didn't load, skip it.
if (empty($asset)) {
continue;
}
// Add an option.
$entity_label = entity_label('farm_asset', $asset);
$asset_options[$asset->id] = htmlspecialchars($entity_label);
}
}
// If there are asset options, add a dropdown.
if (!empty($asset_options)) {
$form['temperature']['asset'] = array(
'#type' => 'select',
'#title' => t('Compost asset'),
'#description' => t('Select the compost asset that this is an observation of.'),
'#options' => $asset_options,
);
}
else {
$form['temperature']['asset'] = array(
'#type' => 'markup',
'#markup' => t('<a href="!add_compost">Add a compost asset</a> before using this form.', array(
'!add_compost' => url('farm/asset/add/compost', array(
'query' => array(
'destination' => current_path(),
),
)),
)),
'#prefix' => '<p>',
'#suffix' => '</p>',
);
return $form;
}
// Determine the unit based on the system of measurement.
// (F for US/Imperial, C for Metric).
$system = farm_quantity_system_of_measurement();
$unit = 'C';
if ($system == 'us') {
$unit = 'F';
}
// Quantity value.
$form['temperature']['value'] = array(
'#type' => 'textfield',
'#title' => t('Temperature'),
'#required' => TRUE,
'#element_validate' => array(
'element_validate_number',
),
'#input_group' => TRUE,
'#field_suffix' => $unit,
);
// Quantity unit.
$form['temperature']['unit'] = array(
'#type' => 'value',
'#value' => $unit,
);
// Submit button.
$form['temperature']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save log'),
);
// Return the form.
return $form;
}