function uc_stock_edit_form in Ubercart 6.2
Same name and namespace in other branches
- 5 uc_stock/uc_stock.module \uc_stock_edit_form()
- 7.3 uc_stock/uc_stock.admin.inc \uc_stock_edit_form()
Form builder for product stock edit form.
See also
1 string reference to 'uc_stock_edit_form'
- uc_stock_menu in uc_stock/
uc_stock.module - Implements hook_menu().
File
- uc_stock/
uc_stock.admin.inc, line 145 - Stock administration menu items.
Code
function uc_stock_edit_form($form_state, $node) {
drupal_set_title(check_plain($node->title));
$form = array();
$form['stock'] = array(
'#tree' => TRUE,
);
$skus = uc_product_get_models($node->nid);
// Remove 'Any'.
unset($skus[NULL]);
if (!$skus) {
drupal_set_message(t('No SKU found.'), 'error');
}
else {
foreach (array_values($skus) as $id => $sku) {
$stock = db_fetch_array(db_query("SELECT * FROM {uc_product_stock} WHERE sku = '%s'", $sku));
$form['stock'][$id]['sku'] = array(
'#type' => 'value',
'#value' => $sku,
);
// Checkbox to mark this as active.
$form['stock'][$id]['active'] = array(
'#type' => 'checkbox',
'#default_value' => !empty($stock['active']) ? $stock['active'] : 0,
);
// Sanitized version of the SKU for display.
$form['stock'][$id]['display_sku'] = array(
'#value' => check_plain($sku),
);
// Textfield for entering the stock level.
$form['stock'][$id]['stock'] = array(
'#type' => 'textfield',
'#default_value' => !empty($stock['stock']) ? $stock['stock'] : 0,
'#maxlength' => 9,
'#size' => 9,
);
// Textfield for entering the threshold level.
$form['stock'][$id]['threshold'] = array(
'#type' => 'textfield',
'#default_value' => !empty($stock['threshold']) ? $stock['threshold'] : 0,
'#maxlength' => 9,
'#size' => 9,
);
}
}
$form['nid'] = array(
'#type' => 'value',
'#value' => $node->nid,
);
$form['save'] = array(
'#type' => 'submit',
'#value' => t('Save changes'),
);
return $form;
}