You are here

function uc_attribute_form_alter in Ubercart 5

Same name and namespace in other branches
  1. 6.2 uc_attribute/uc_attribute.module \uc_attribute_form_alter()

Implementation of hook_form_alter().

Attach option selectors to the form with the "Add to Cart" button.

File

uc_attribute/uc_attribute.module, line 244

Code

function uc_attribute_form_alter($form_id, &$form) {
  if (strpos($form_id, 'add_to_cart_form') || strpos($form_id, 'add_product_form')) {

    // If the node has a product list, add attributes to them
    if (count(element_children($form['products']))) {
      foreach (element_children($form['products']) as $key) {
        $form['products'][$key] = _uc_attribute_alter_form($form['products'][$key]);
        if (isset($form['products'][$key]['attributes'])) {
          $form['products'][$key]['attributes']['#tree'] = true;
          $form['products'][$key]['#type'] = 'fieldset';
        }
      }
    }
    else {
      $form['attributes'] = array(
        '#tree' => true,
        '#weight' => -1,
      );
      $form = _uc_attribute_alter_form($form);
    }
  }
}