function uc_dropdown_attributes_remove_values in Dropdown Attributes 8
Same name and namespace in other branches
- 7 uc_dropdown_attributes.module \uc_dropdown_attributes_remove_values()
Unset values of orphaned children.
Called recursively to remove orphaned values from form_state.
Parameters
int $parent_aid: Attribute ID of the triggering element.
int $parent_value: Option ID of the value of the triggering element.
int $id: Node ID or product class ID.
string $type: Type of 'node' or 'class'.
array $form_values: Part of the form_state array containing the attributes.
7 calls to uc_dropdown_attributes_remove_values()
- _uc_dropdown_attributes_class_build in ./
uc_dropdown_attributes.module - Form build for classes.
- _uc_dropdown_attributes_kit_build in ./
uc_dropdown_attributes.module - Form build for product kits.
- _uc_dropdown_attributes_order_class_build in ./
uc_dropdown_attributes.module - Form build for classes for the order page.
- _uc_dropdown_attributes_order_class_kit_build in ./
uc_dropdown_attributes.module - Form build for classes in product kits for the order page.
- _uc_dropdown_attributes_order_product_build in ./
uc_dropdown_attributes.module - Form build for products for the order page.
File
- ./
uc_dropdown_attributes.module, line 530 - A module for uc_dropdown_attributes.
Code
function uc_dropdown_attributes_remove_values($parent_aid, $parent_value, $id, $type, &$form_values) {
switch ($type) {
case 'node':
$children = \Drupal::database()
->select('uc_dropdown_products', 'products')
->fields('products', array(
'aid',
'required',
'parent_values',
))
->condition('products.nid', $id)
->condition('products.parent_aid', $parent_aid)
->execute();
break;
case 'class':
$children = \Drupal::database()
->select('uc_dropdown_classes', 'classes')
->fields('classes', array(
'aid',
'required',
'parent_values',
))
->condition('classes.pcid', $id)
->condition('classes.parent_aid', $parent_aid)
->execute();
break;
default:
$children = array();
break;
}
foreach ($children as $child) {
if ($child->required) {
$value = $form_values['attributes'][$child->aid];
$form_values['attributes'][$child->aid] = '';
if ($value) {
$values = unserialize($child->parent_values);
if (!in_array($parent_value, $values)) {
uc_dropdown_attributes_remove_values($child->aid, $value, $id, $type, $form_values);
}
}
}
}
}