You are here

function uc_attribute_option_form in Ubercart 6.2

Same name and namespace in other branches
  1. 5 uc_attribute/uc_attribute.module \uc_attribute_option_form()
  2. 7.3 uc_attribute/uc_attribute.admin.inc \uc_attribute_option_form()

Form builder for attribute options.

See also

uc_attribute_option_form_validate()

uc_attribute_option_form_submit()

1 string reference to 'uc_attribute_option_form'
uc_attribute_menu in uc_attribute/uc_attribute.module
Implements hook_menu().

File

uc_attribute/uc_attribute.admin.inc, line 470
Attribute administration menu items.

Code

function uc_attribute_option_form($form_state, $attribute, $option = NULL) {

  // If we got a bunk attribute, kick out an error message.
  if (empty($attribute)) {
    drupal_set_message(t('There is no attribute with that ID.'), 'error');
    drupal_goto('admin/store/attributes');
  }
  $aid = $attribute->aid;
  $form['aid'] = array(
    '#type' => 'hidden',
    '#value' => $aid,
  );
  if (!empty($option)) {
    $form['oid'] = array(
      '#type' => 'hidden',
      '#value' => $option->oid,
    );
    drupal_set_title(t('Edit option: %name', array(
      '%name' => $option->name,
    )));
  }
  else {
    $option = new stdClass();
    $option->name = '';
    $option->ordering = 0;
    $option->cost = 0;
    $option->price = 0;
    $option->weight = 0;
    drupal_set_title(t('Options for %name', array(
      '%name' => $attribute->name,
    )));
  }
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#description' => t('This name will appear to customers on product add to cart forms.'),
    '#default_value' => $option->name,
    '#required' => TRUE,
    '#weight' => 0,
  );
  $form['ordering'] = array(
    '#type' => 'weight',
    '#delta' => 50,
    '#title' => t('List position'),
    '#description' => t('Options will be listed sorted by this value and then by their name.<br />May be overridden at the product level.'),
    '#default_value' => isset($option->ordering) ? $option->ordering : 0,
    '#weight' => 4,
  );
  $form['adjustments'] = array(
    '#type' => 'fieldset',
    '#title' => t('Default adjustments'),
    '#description' => t('Enter a positive or negative value for each adjustment applied when this option is selected.<br />Any of these may be overriden at the product level.'),
    '#collapsible' => FALSE,
    '#weight' => 8,
  );
  $form['adjustments']['cost'] = array(
    '#type' => 'textfield',
    '#title' => t('Cost'),
    '#default_value' => uc_store_format_price_field_value($option->cost),
    '#weight' => 1,
  );
  $form['adjustments']['price'] = array(
    '#type' => 'textfield',
    '#title' => t('Price'),
    '#default_value' => uc_store_format_price_field_value($option->price),
    '#weight' => 2,
  );
  $form['adjustments']['weight'] = array(
    '#type' => 'textfield',
    '#title' => t('Weight'),
    '#default_value' => $option->weight,
    '#weight' => 3,
  );
  if (isset($form['oid'])) {
    $form['bulk_update'] = array(
      '#type' => 'checkbox',
      '#title' => t('Update existing products?'),
      '#description' => t('If selected, existing products and product classes with this attribute will be updated with the values on this page.<br /><em><strong>Warning:</strong> any option adjustments set at the product level will be overridden!</em>'),
      '#default_value' => 0,
      '#weight' => 4,
    );
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
    '#suffix' => l(t('Cancel'), 'admin/store/attributes/' . $aid . '/options'),
    '#weight' => 10,
  );
  return $form;
}