function _uc_dropdown_attributes_order_product_kit_build in Dropdown Attributes 8
Same name and namespace in other branches
- 7 uc_dropdown_attributes.module \_uc_dropdown_attributes_order_product_kit_build()
Form build for product kits for the order page.
Callback for $form['#after_build'] for products. Adds the CSS to hide the dependent attributes.
File
- ./
uc_dropdown_attributes.module, line 1062 - A module for uc_dropdown_attributes.
Code
function _uc_dropdown_attributes_order_product_kit_build($form, &$form_state) {
foreach ($form['product_controls']['sub_products'] as $nid => $product) {
if (is_numeric($nid)) {
$type = uc_dropdown_attributes_dependency_type($nid);
switch ($type) {
case 'node':
$fields = array(
'aid',
'parent_aid',
'parent_values',
'required',
);
$attributes = \Drupal::database()
->select('uc_dropdown_products', 'products')
->fields('products', $fields)
->condition('products.nid', $nid)
->execute();
$trigger = $form_state
->getTriggeringElement();
if (!is_null($trigger) && $nid == $trigger['#parents'][2]) {
$parents = $trigger['#parents'];
$parent_aid = $parents[count($parents) - 1];
$parent_value = $trigger['#value'];
uc_dropdown_attributes_remove_values($parent_aid, $parent_value, $nid, 'node', $form_state['values']['product_controls']['sub_products'][$nid]);
}
uc_dropdown_attributes_order_attribute_display($attributes, $form['product_controls']['sub_products'][$nid]['attributes'], $form_state['values']['product_controls']['sub_products'][$nid]['attributes'], $form_state);
break;
case 'class':
$pcid = uc_dropdown_attributes_get_type($nid);
$fields = array(
'aid',
'parent_aid',
'parent_values',
'required',
);
$attributes = \Drupal::database()
->select('uc_dropdown_classes', 'classes')
->fields('classes', $fields)
->condition('classes.pcid', $pcid)
->execute();
$trigger = $form_state
->getTriggeringElement();
if (!is_null($trigger) && $nid == $trigger['#parents'][2]) {
$parents = $trigger['#parents'];
$parent_aid = $parents[count($parents) - 1];
$parent_value = $trigger['#value'];
// Note that values are stored in input, not values.
uc_dropdown_attributes_remove_values($parent_aid, $parent_value, $pcid, 'class', $form_state['input']['product_controls']['sub_products'][$nid]);
}
uc_dropdown_attributes_order_attribute_display($attributes, $form['product_controls']['sub_products'][$nid]['attributes'], $form_state['values']['product_controls']['sub_products'][$nid]['attributes'], $form_state);
break;
}
}
}
return $form;
}