function units_unit_form in Units of Measurement 7.2
Same name and namespace in other branches
- 7 units_ui.pages.inc \units_unit_form()
Generate editing form for entity type 'units_unit'.
File
- ./
units_ui.pages.inc, line 93 - Menu page callbacks for Units UI module.
Code
function units_unit_form($form, &$form_state, $entity, $op = 'edit') {
if ($op == 'clone') {
$entity->label .= ' (cloned)';
}
$form['label'] = array(
'#type' => 'textfield',
'#title' => t('Label'),
'#required' => TRUE,
'#description' => t('Provide human readable label of this measurement unit.'),
'#default_value' => isset($entity->label) ? $entity->label : NULL,
);
$form['machine_name'] = array(
'#type' => 'machine_name',
'#maxlength' => 32,
'#machine_name' => array(
'exists' => 'units_unit_machine_name_load',
'source' => array(
'label',
),
),
'#description' => t('A unique machine-readable name for this measurement unit. It must only contain lowercase letters, numbers, and underscores.'),
'#default_value' => isset($entity->machine_name) ? $entity->machine_name : NULL,
);
$form['symbol'] = array(
'#type' => 'textfield',
'#title' => t('Symbol'),
'#description' => t('Provide human readable symbol of this measurement unit.'),
'#default_value' => isset($entity->symbol) ? $entity->symbol : NULL,
);
$form['description'] = array(
'#type' => 'textarea',
'#title' => t('Description'),
'#description' => t('Provide description of this measurement unit.'),
'#default_value' => isset($entity->description) ? $entity->description : NULL,
);
$form['is_composed'] = array(
'#type' => 'checkbox',
'#title' => t('This is a composed unit that can be decomposed into other units'),
'#default_value' => isset($entity->decomposition),
);
$form['decomposition'] = array(
'#type' => 'units_mathematical_expression',
'#title' => t('Decomposition'),
'#description' => t('Specify here formula, according to which this unit of measure decomposes into other units. If this unit is not linear, i.e. there is no way to convert this unit into another through multiplication, then use %quantity placeholder in the formula to denote the quantity of this unit.', array(
'%quantity' => UNITS_QUANTITY,
)),
'#default_value' => $entity->decomposition,
'#value_format' => 'object',
'#states' => array(
'visible' => array(
':checkbox[name="is_composed"]' => array(
'checked' => TRUE,
),
),
),
);
field_attach_form('units_unit', $entity, $form, $form_state);
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save unit'),
);
if ($op != 'add' && $op != 'clone') {
$form['actions']['delete'] = array(
'#type' => 'submit',
'#value' => t('Delete unit'),
'#limit_validation_errors' => array(),
'#submit' => array(
'units_unit_form_delete_submit',
),
);
}
return $form;
}