You are here

function uc_dropdown_attributes_product_submit in Dropdown Attributes 7

Same name and namespace in other branches
  1. 6 dependent_dropdown.inc \uc_dropdown_attributes_product_submit()

Form submission handler for uc_dropdown_attributes_product().

Write form values out to the database table.

File

./dependent_dropdown.inc, line 47
Administrative interface for specifying the attribute dependencies.

Code

function uc_dropdown_attributes_product_submit($form, &$form_state) {
  if ($form_state['clicked_button']['#id'] == 'edit-submit') {
    $form_state['rebuild'] = FALSE;
    $nid = $form_state['build_info']['args'][0]->nid;
    if (isset($form_state['values']['attributes'])) {
      $values = $form_state['values']['attributes'];
      $attributes = _uc_dropdown_attributes_extract_attributes($values);
    }
    else {
      $attributes = array();
    }
    $result = db_delete('uc_dropdown_attributes')
      ->condition('nid', $nid)
      ->execute();
    drupal_set_message(t('Processing node :nid', array(
      ':nid' => $nid,
    )));
    foreach ($attributes as $aid => $attribute) {
      if ($attribute->parent_aid != 0) {
        uc_dropdown_attributes_product_create_dependency($nid, $aid, $attribute->parent_aid, $attribute->parent_values, $attribute->required);
        drupal_set_message(t('Saved :name', array(
          ':name' => $attribute->name,
        )));
      }
    }
  }

  // edit-next or anything else will cause rebuild.
  $form_state['rebuild'] = TRUE;
}