function uc_attribute_option_ajax in Ubercart 8.4
Same name and namespace in other branches
- 7.3 uc_attribute/uc_attribute.module \uc_attribute_option_ajax()
Ajax callback for attribute selection form elements.
1 string reference to 'uc_attribute_option_ajax'
- _uc_attribute_alter_form in uc_attribute/
uc_attribute.module - Helper function for uc_attribute_form_alter().
File
- uc_attribute/
uc_attribute.module, line 1139 - Ubercart Attribute module.
Code
function uc_attribute_option_ajax($form, FormStateInterface $form_state) {
$response = new AjaxResponse();
$triggering_element = $form_state
->getTriggeringElement();
$parents = $triggering_element['#array_parents'];
$wrapper = '#' . $triggering_element['#ajax']['wrapper'];
while ($key = array_pop($parents)) {
if ($key == 'attributes') {
array_push($parents, $key);
$element = NestedArray::getValue($form, $parents);
$response
->addCommand(new ReplaceCommand($wrapper, drupal_render($element)));
break;
}
}
if (strpos($form['#form_id'], 'add_to_cart_form') !== FALSE) {
uc_product_view_ajax_commands($response, $form_state, [
'display_price',
'weight',
'cost',
]);
}
$status_messages = [
'#type' => 'status_messages',
];
$response
->addCommand(new PrependCommand($wrapper, drupal_render($status_messages)));
return $response;
}