function _uc_dropdown_attributes_order_class_kit_build in Dropdown Attributes 7
Same name and namespace in other branches
- 8 uc_dropdown_attributes.module \_uc_dropdown_attributes_order_class_kit_build()
Form build for classes in product kits for the order page.
Callback for $form['#after_build'] for product classes. Adds the CSS to hide the dependent attributes.
File
- ./
uc_dropdown_attributes.module, line 1052 - Show/hide attributes based on the values of other attributes.
Code
function _uc_dropdown_attributes_order_class_kit_build($form, &$form_state) {
$sql = 'SELECT aid, parent_aid, parent_values, required
FROM {uc_dropdown_classes} WHERE pcid=:pcid';
$pcid = uc_dropdown_attributes_get_type($form['nid']['#value']);
$attributes = db_query($sql, array(
':pcid' => $pcid,
));
if (isset($form_state['triggering_element'])) {
$parents = $form_state['triggering_element']['#parents'];
$parent_aid = $parents[count($parents) - 1];
$parent_value = $form_state['triggering_element']['#value'];
uc_dropdown_attributes_remove_values($parent_aid, $parent_value, $pcid, 'class', $form_state['values']['product_controls']);
}
foreach ($attributes as $attribute) {
$parent_value = $form_state['values']['product_controls']['attributes'][$attribute->parent_aid];
if ($parent_value) {
// A value has been entered in parent attribute.
$values = unserialize($attribute->parent_values);
if (array_key_exists($parent_value, $values)) {
// Show dependent attribute.
if ($attribute->required) {
$form['product_controls']['attributes'][$attribute->aid]['#required'] = TRUE;
}
}
else {
// Hide dependent attribute.
$form['product_controls']['attributes'][$attribute->aid]['#post_render'][] = 'uc_dropdown_attributes_post_render';
if ($form['product_controls']['attributes'][$attribute->aid]['#required'] && $form['product_controls']['attributes'][$attribute->aid]['#value'] != '') {
$form['product_controls']['attributes'][$attribute->aid]['#value'] = '';
}
}
}
else {
$form['product_controls']['attributes'][$attribute->aid]['#post_render'][] = 'uc_dropdown_attributes_post_render';
if ($form['product_controls']['attributes'][$attribute->aid]['#required'] && $form['product_controls']['attributes'][$attribute->aid]['#value'] != '') {
$form['product_controls']['attributes'][$attribute->aid]['#value'] = '';
}
}
}
return $form;
}