function uc_product_class_form_submit in Ubercart 7.3
Same name and namespace in other branches
- 5 uc_product/uc_product.module \uc_product_class_form_submit()
- 6.2 uc_product/uc_product.admin.inc \uc_product_class_form_submit()
Form submission handler for uc_product_class_form().
See also
uc_product_class_form_validate()
File
- uc_product/
uc_product.admin.inc, line 373 - Product administration menu items.
Code
function uc_product_class_form_submit($form, &$form_state) {
$is_new = $form['pcid']['#type'] == 'textfield';
$pcid = $form_state['values']['pcid'];
// Convert whitespace to underscores, and remove other non-alphanumeric characters.
$pcid = preg_replace(array(
'/\\s+/',
'/\\W/',
), array(
'_',
'',
), strtolower($pcid));
$result = db_merge('uc_product_classes')
->key(array(
'pcid' => $pcid,
))
->fields(array(
'name' => $form_state['values']['name'],
'description' => $form_state['values']['description'],
))
->execute();
db_update('node_type')
->fields(array(
'name' => $form_state['values']['name'],
'description' => $form_state['values']['description'],
))
->condition('type', $pcid)
->execute();
uc_product_node_info(TRUE);
if ($result == MergeQuery::STATUS_INSERT) {
variable_set('node_options_' . $pcid, variable_get('node_options_product', array(
'status',
'promote',
)));
if (module_exists('comment')) {
variable_set('comment_' . $pcid, variable_get('comment_product', COMMENT_NODE_OPEN));
}
module_invoke_all('uc_product_class', $pcid, 'insert');
}
else {
module_invoke_all('uc_product_class', $pcid, 'update');
}
node_types_rebuild();
if ($is_new) {
$type = node_type_get_type($pcid);
node_add_body_field($type, t('Description'));
uc_product_add_default_image_field($pcid);
}
menu_rebuild();
drupal_set_message(t('Product class saved.'));
}