function _uc_dropdown_attributes_order_class_build in Dropdown Attributes 8
Same name and namespace in other branches
- 7 uc_dropdown_attributes.module \_uc_dropdown_attributes_order_class_build()
Form build for classes for the order page.
Callback for $form['#after_build'] for product classes. Adds the CSS to hide the dependent attributes.
1 string reference to '_uc_dropdown_attributes_order_class_build'
- uc_dropdown_attributes_form_uc_order_edit_form_alter in ./
uc_dropdown_attributes.module - Implements hook_form_FORM_ID_alter() for uc_order_edit_form().
File
- ./
uc_dropdown_attributes.module, line 1002 - A module for uc_dropdown_attributes.
Code
function _uc_dropdown_attributes_order_class_build($form, &$form_state) {
$pcid = uc_dropdown_attributes_get_type($form['products']['product_controls']['nid']['#value']);
$attributes = \Drupal::database()
->select('uc_dropdown_classes', 'classes')
->fields('classes', array(
'aid',
'parent_aid',
'parent_values',
'required',
))
->condition('classes.pcid', $pcid)
->execute();
$form_values = $form_state
->getValues();
$trigger = $form_state
->getTriggeringElement();
if (!is_null($trigger)) {
$parents = $trigger['#parents'];
$parent_aid = $parents[2];
if (is_numeric($parent_aid)) {
$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_values['product_controls']);
}
}
foreach ($attributes as $attribute) {
$parent_value = $form_values['product_controls']['attributes'][$attribute->parent_aid];
$values = unserialize($attribute->parent_values);
if ($form['products']['product_controls']['attributes'][$attribute->parent_aid]['#type'] == 'checkboxes') {
$parent_values = array_diff($parent_value, array(
0,
));
if (count(array_intersect($parent_values, $values)) == 0) {
uc_dropdown_attributes_hide_attribute($form['products']['product_controls'], $attribute->aid);
if ($attribute->required) {
uc_dropdown_attributes_clear_input($form['products']['product_controls'], $form_state, $attribute->aid);
}
}
}
else {
if (is_numeric($parent_value)) {
if (!in_array($parent_value, $values)) {
uc_dropdown_attributes_hide_attribute($form['products']['product_controls'], $attribute->aid);
if ($attribute->required) {
uc_dropdown_attributes_clear_input($form['products']['product_controls'], $form_state, $attribute->aid);
}
}
}
else {
uc_dropdown_attributes_hide_attribute($form['products']['product_controls'], $attribute->aid);
if ($attribute->required) {
uc_dropdown_attributes_clear_input($form['products']['product_controls'], $form_state, $attribute->aid);
}
}
}
}
return $form;
}