You are here

function uc_dropdown_attributes_form_alter in Dropdown Attributes 7

Same name and namespace in other branches
  1. 8 uc_dropdown_attributes.module \uc_dropdown_attributes_form_alter()
  2. 6 uc_dropdown_attributes.module \uc_dropdown_attributes_form_alter()

Implements hook_form_alter().

File

./uc_dropdown_attributes.module, line 53
Show/hide attributes based on the values of other attributes.

Code

function uc_dropdown_attributes_form_alter(&$form, &$form_state, $form_id) {
  if (preg_match('/^uc_product_kit_add_to_cart_form.*/', $form_id)) {
    foreach ($form['products'] as $key => $value) {
      if (is_numeric($key)) {
        $type = uc_dropdown_attributes_dependency_type($key);
        if (!is_null($type)) {
          if (isset($form_state['values'])) {
            $values = $form_state['values'];
          }
          else {
            $values = array();
          }
          uc_dropdown_attributes_product_alter($key, $form['products'][$key], $values, $type, $form_state['rebuild']);

          // Make sure these have not been added more than once.
          if (!isset($form['#after_build']) || !in_array('_uc_dropdown_attributes_kit_build', $form['#after_build'])) {
            $form['#after_build'][] = '_uc_dropdown_attributes_kit_build';
          }
        }
      }
    }
  }
  if (preg_match('/^uc_product_add_to_cart_form.*/', $form_id)) {
    $nid = $form['nid']['#value'];
    $type = uc_dropdown_attributes_dependency_type($nid);
    if (!is_null($type)) {
      if (isset($form_state['values'])) {
        $values = $form_state['values'];
      }
      else {
        $values = array();
      }
      uc_dropdown_attributes_product_alter($nid, $form, $values, $type, $form_state['rebuild']);
      $form['node_id'] = array(
        '#type' => 'hidden',
        '#value' => $nid,
      );
      switch ($type) {
        case 'node':
          $form['#after_build'][] = '_uc_dropdown_attributes_product_build';
          break;
        case 'class':
          $form['#after_build'][] = '_uc_dropdown_attributes_class_build';
          break;
      }
    }
  }
}