You are here

function units_measure_form in Units of Measurement 7.2

Same name and namespace in other branches
  1. 7 units_ui.pages.inc \units_measure_form()

Generate editing form for entity type 'units_measure'.

File

./units_ui.pages.inc, line 11
Menu page callbacks for Units UI module.

Code

function units_measure_form($form, &$form_state, $entity, $op = 'edit') {
  if ($op == 'clone') {
    $entity->label .= ' (cloned)';
  }
  $form['label'] = array(
    '#type' => 'textfield',
    '#title' => t('Label'),
    '#description' => t('The human-readable name of this measure.'),
    '#required' => TRUE,
    '#default_value' => isset($entity->label) ? $entity->label : NULL,
  );
  $form['measure'] = array(
    '#type' => 'machine_name',
    '#maxlength' => 32,
    '#machine_name' => array(
      'exists' => 'units_measure_machine_name_load',
      'source' => array(
        'label',
      ),
    ),
    '#description' => t('A unique machine-readable name for this measure. It must only contain lowercase letters, numbers, and underscores.'),
    '#default_value' => isset($entity->measure) ? $entity->measure : '',
  );
  $form['description'] = array(
    '#type' => 'textarea',
    '#title' => t('Description'),
    '#description' => t('Please, provide description of the measure.'),
    '#default_value' => isset($entity->description) ? $entity->description : NULL,
  );
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save measure'),
  );
  if ($op != 'add' && $op != 'clone') {
    $form['actions']['delete'] = array(
      '#type' => 'submit',
      '#value' => t('Delete measure'),
      '#limit_validation_errors' => array(),
      '#submit' => array(
        'units_measure_form_delete_submit',
      ),
    );
  }
  return $form;
}