You are here

function commerce_option_set_form in Commerce Product Option 7.2

Same name and namespace in other branches
  1. 7 includes/commerce_option_set.forms.inc \commerce_option_set_form()

Commerce Option Set edit/create form.

File

./commerce_option.admin.inc, line 184

Code

function commerce_option_set_form($form, &$form_state, $option_set, $op = 'edit') {
  if ($op == 'clone') {
    $option_set->name .= ' (cloned)';
    $option_set->set_id = '';
  }
  $form['data']['#tree'] = TRUE;

  // Human-readable name.
  $form['name'] = array(
    '#title' => t('Name'),
    '#type' => 'textfield',
    '#default_value' => isset($option_set->name) ? $option_set->name : '',
    '#description' => t('The human-readable name of this option set.'),
    '#required' => TRUE,
    '#size' => 30,
  );

  // Machine-readable name.
  $form['set_id'] = array(
    '#type' => 'machine_name',
    '#default_value' => isset($option_set->set_id) ? $option_set->set_id : '',
    '#maxlength' => 32,
    '#disabled' => !empty($option_set->set_id) ? TRUE : FALSE,
    '#machine_name' => array(
      'exists' => 'commerce_option_set_load_by_name',
      'source' => array(
        'name',
      ),
    ),
    '#description' => t('A unique machine-readable name for this option set. It must only contain lowercase letters, numbers, and underscores.'),
  );

  // Description.
  $form['description'] = array(
    '#type' => 'textarea',
    '#default_value' => isset($option_set->description) ? $option_set->description : '',
    '#title' => t('Description'),
    '#description' => t('This description is shown to the admin user to indicate if this option set is useful for the current purpose.'),
  );

  // Actions.
  $form['actions'] = array(
    '#type' => 'actions',
    'submit' => array(
      '#type' => 'submit',
      '#value' => t('Save option set'),
      '#weight' => 40,
    ),
  );
  if ($op != 'add') {
    $form['actions']['delete'] = array(
      '#type' => 'submit',
      '#value' => t('Delete option set'),
      '#weight' => 45,
      '#limit_validation_errors' => array(),
      '#submit' => array(
        'commerce_option_set_form_submit_delete',
      ),
    );
  }
  return $form;
}