You are here

function uc_dropdown_attributes_clear_input in Dropdown Attributes 8

Same name and namespace in other branches
  1. 7 uc_dropdown_attributes.module \uc_dropdown_attributes_clear_input()

Clear inputs for attribute.

Parameters

array $form: Form array.

array $form_state: Form state array.

int $aid: Attribute ID.

int $id: Node or product class ID.

6 calls to uc_dropdown_attributes_clear_input()
uc_dropdown_attributes_order_attribute_display in ./uc_dropdown_attributes.module
Alter display of attributes on the order page.
_uc_dropdown_attributes_class_build in ./uc_dropdown_attributes.module
Form build for classes.
_uc_dropdown_attributes_kit_build in ./uc_dropdown_attributes.module
Form build for product kits.
_uc_dropdown_attributes_order_class_build in ./uc_dropdown_attributes.module
Form build for classes for the order page.
_uc_dropdown_attributes_order_product_build in ./uc_dropdown_attributes.module
Form build for products for the order page.

... See full list

File

./uc_dropdown_attributes.module, line 317
A module for uc_dropdown_attributes.

Code

function uc_dropdown_attributes_clear_input(&$form, &$form_state, $aid, $id = NULL) {
  switch ($form['attributes'][$aid]['#type']) {
    case 'checkboxes':
      $input =& $form_state
        ->getUserInput();
      if (isset($input['product_controls'])) {
        foreach ($input['product_controls']['attributes'][$aid] as $oid => $value) {
          $input['product_controls']['attributes'][$aid][$oid] = NULL;
        }
      }
      else {
        if (is_null($id)) {
          if (isset($input['attributes'])) {
            foreach ($input['attributes'][$aid] as $oid => $value) {
              $input['attributes'][$aid][$oid] = NULL;
            }
          }
        }
        else {
          if (isset($input['products'][$id]['attributes'])) {
            foreach ($input['products'][$id]['attributes'][$aid] as $oid => $value) {
              $input['products'][$id]['attributes'][$aid][$oid] = NULL;
            }
          }
        }
      }
      $form_state
        ->setUserInput($input);
      break;
    case 'radios':
    case 'textfield':
      $input =& $form_state
        ->getUserInput();
      if (isset($input['product_controls'])) {
        $input['product_controls']['attributes'][$aid] = NULL;
      }
      else {
        if (is_null($id)) {
          $input['attributes'][$aid] = NULL;
        }
        else {
          $input['products'][$id]['attributes'][$aid] = NULL;
        }
      }
      $form_state
        ->setUserInput($input);
      break;
    case 'select':
      if ($form['attributes'][$aid]['#value'] != '') {
        $form['attributes'][$aid]['#value'] = '';
      }
      break;
    default:
      break;
  }
}