function _uc_dropdown_attributes_class_build in Dropdown Attributes 8
Same name and namespace in other branches
- 7 uc_dropdown_attributes.module \_uc_dropdown_attributes_class_build()
Form build for classes.
Callback for $form['#after_build'] for product classes. Adds the CSS to hide the dependent attributes.
1 string reference to '_uc_dropdown_attributes_class_build'
- uc_dropdown_attributes_form_alter in ./
uc_dropdown_attributes.module - Implements hook_form_alter().
File
- ./
uc_dropdown_attributes.module, line 379 - A module for uc_dropdown_attributes.
Code
function _uc_dropdown_attributes_class_build($form, &$form_state) {
$pcid = uc_dropdown_attributes_get_type($form['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[1];
$parent_value = $trigger['#value'];
uc_dropdown_attributes_remove_values($parent_aid, $parent_value, $pcid, 'class', $form_values);
}
if (isset($form_values['attributes'])) {
foreach ($attributes as $attribute) {
$parent_value = $form_values['attributes'][$attribute->parent_aid];
$values = unserialize($attribute->parent_values);
if ($form['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, $attribute->aid);
if ($attribute->required) {
uc_dropdown_attributes_clear_input($form, $form_state, $attribute->aid);
}
}
}
else {
if (is_numeric($parent_value)) {
if (!in_array($parent_value, $values)) {
uc_dropdown_attributes_hide_attribute($form, $attribute->aid);
if ($attribute->required) {
uc_dropdown_attributes_clear_input($form, $form_state, $attribute->aid);
}
}
}
else {
uc_dropdown_attributes_hide_attribute($form, $attribute->aid);
if ($attribute->required) {
uc_dropdown_attributes_clear_input($form, $form_state, $attribute->aid);
}
}
}
}
}
return $form;
}