function commerce_ss_admin_form in Commerce Stock 7.2
Commerce Stock admin form.
1 string reference to 'commerce_ss_admin_form'
- commerce_ss_menu in modules/
commerce_ss/ commerce_ss.module - Implements hook_menu().
File
- modules/
commerce_ss/ includes/ commerce_ss.admin.inc, line 11 - Administrative callbacks and form builder functions for Commerce Stock.
Code
function commerce_ss_admin_form($form, &$form_state) {
// Find out what our status is. Use both the state of existing fields
// and the state of variables to determine what's right.
$field_name = 'commerce_stock';
$field = field_info_field($field_name);
$form['#tree'] = TRUE;
$form['product_types'] = array(
'#type' => 'fieldset',
'#title' => t('Enable stock management for these product types'),
'#description' => t('Note that disabling stock management removes the Stock field from the product type, deleting any existing stock data for that product type.'),
);
$form['product_types_override'] = array(
'#type' => 'fieldset',
'#title' => t('Enable stock management override for these product types'),
'#description' => t('Note that disabling stock management override removes the Stock override field from the product type, deleting any existing stock override data for that product type.'),
);
// Create a checkbox for each product type, set with the current stock-
// enabled state.
foreach (commerce_product_types() as $type => $product_type) {
$instance[$type] = field_info_instance('commerce_product', 'commerce_stock', $type);
$enabled[$type] = !empty($instance[$type]);
$form['product_types'][$type] = array(
'#type' => 'checkbox',
'#default_value' => $enabled[$type],
'#title' => t('@name (@machine_name)', array(
'@name' => $product_type['name'],
'@machine_name' => $type,
)),
);
if ($enabled[$type]) {
$instance[$type] = field_info_instance('commerce_product', 'commerce_stock_override', $type);
$enabled[$type] = !empty($instance[$type]);
$form['product_types_override'][$type] = array(
'#type' => 'checkbox',
'#default_value' => $enabled[$type],
'#title' => t('Allow stock override for @name (@machine_name)', array(
'@name' => $product_type['name'],
'@machine_name' => $type,
)),
);
}
}
// Add a checkbox that requires them to say "I do", but don't show it
// (#access == FALSE) unless they're deleting.
if (!empty($form_state['commerce_stock']['delete_instances'])) {
$type_plural = format_plural(count($form_state['commerce_stock']['delete_instances']), t('type'), t('types'));
$affirmation = t('I understand that all stock data will be permanently removed from the product @type_plural %product_types.', array(
'@type_plural' => $type_plural,
'%product_types' => implode(', ', $form_state['commerce_stock']['delete_instances']),
));
}
$form['confirmation'] = array(
'#type' => 'checkbox',
'#title' => !empty($affirmation) ? $affirmation : '',
'#default_value' => FALSE,
'#access' => FALSE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
// If they're deleting, show the confirmation checkbox.
if (!empty($form_state['commerce_stock']['delete_instances'])) {
$form['confirmation']['#access'] = TRUE;
drupal_set_message(t('You must click the confirmation checkbox to confirm that you want to delete stock data'), 'warning');
}
return $form;
}