function uc_dropdown_attributes_form_alter in Dropdown Attributes 6
Same name and namespace in other branches
- 8 uc_dropdown_attributes.module \uc_dropdown_attributes_form_alter()
- 7 uc_dropdown_attributes.module \uc_dropdown_attributes_form_alter()
Implements hook_form_alter().
File
- ./
uc_dropdown_attributes.module, line 73 - Show/hide attributes based on the values of other attributes.
Code
function uc_dropdown_attributes_form_alter(&$form, &$form_state, $form_id) {
if (preg_match('/^uc_product_kit_add_to_cart_form.*/', $form_id)) {
foreach ($form['products'] as $key => $value) {
if (is_numeric($key)) {
$type = uc_dropdown_attributes_dependency_type($key);
if (!is_null($type)) {
uc_dropdown_attributes_product_alter($key, $form['products'][$key]['attributes'], $type);
// Make sure these have not been added more than once.
if (!isset($form['#validate']) || !in_array('uc_dropdown_attributes_validate', $form['#validate'])) {
$form['#validate'][] = 'uc_dropdown_attributes_validate';
}
if (!isset($form['#after_build']) || !in_array('uc_dropdown_attributes_build', $form['#after_build'])) {
$form['#after_build'][] = 'uc_dropdown_attributes_build';
}
}
}
}
}
if (preg_match('/^uc_product_add_to_cart_form.*/', $form_id)) {
$nid = $form['nid']['#value'];
$type = uc_dropdown_attributes_dependency_type($nid);
if (!is_null($type)) {
uc_dropdown_attributes_product_alter($nid, $form['attributes'], $type);
$form['node_id'] = array(
'#type' => 'hidden',
'#value' => $nid,
);
$form['#after_build'][] = 'uc_dropdown_attributes_build';
$form['#validate'][] = 'uc_dropdown_attributes_validate';
}
}
}