function commerce_product_ui_product_type_form in Commerce Core 7
Form callback: create or edit a product type.
Parameters
$product_type: The product type array to edit or for a create form an empty product type array with properties instantiated but not populated.
1 string reference to 'commerce_product_ui_product_type_form'
- commerce_product_ui_product_type_form_wrapper in modules/
product/ includes/ commerce_product_ui.types.inc - Form callback wrapper: create or edit a product type.
File
- modules/
product/ includes/ commerce_product_ui.forms.inc, line 16 - Forms for creating / editing and deleting products.
Code
function commerce_product_ui_product_type_form($form, &$form_state, $product_type) {
// Ensure this include file is loaded when the form is rebuilt from the cache.
$form_state['build_info']['files']['form'] = drupal_get_path('module', 'commerce_product_ui') . '/includes/commerce_product_ui.forms.inc';
// Store the initial product type in the form state.
$form_state['product_type'] = $product_type;
$form['product_type'] = array(
'#tree' => TRUE,
);
$form['product_type']['name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
'#default_value' => $product_type['name'],
'#description' => t('The human-readable name of this product type. It is recommended that this name begin with a capital letter and contain only letters, numbers, and spaces. This name must be unique.'),
'#required' => TRUE,
'#size' => 32,
);
if (empty($product_type['type'])) {
$form['product_type']['type'] = array(
'#type' => 'machine_name',
'#title' => t('Machine name'),
'#default_value' => $product_type['type'],
'#maxlength' => 32,
'#required' => TRUE,
'#machine_name' => array(
'exists' => 'commerce_product_type_load',
'source' => array(
'product_type',
'name',
),
),
'#description' => t('The machine-readable name of this product type. This name must contain only lowercase letters, numbers, and underscores, it must be unique.'),
);
}
$form['product_type']['description'] = array(
'#type' => 'textarea',
'#title' => t('Description'),
'#description' => t('Describe this product type. The text will be displayed on the <em>Add new content</em> page.'),
'#default_value' => $product_type['description'],
'#rows' => 3,
);
$form['product_type']['help'] = array(
'#type' => 'textarea',
'#title' => t('Explanation or submission guidelines'),
'#description' => t('This text will be displayed at the top of the page when creating or editing products of this type.'),
'#default_value' => $product_type['help'],
'#rows' => 3,
);
$form['product_type']['revision'] = array(
'#type' => 'checkbox',
'#title' => t('Default products of this type to be saved as new revisions when edited.'),
'#default_value' => $product_type['revision'],
);
if (module_exists('entity_translation')) {
$form['product_type']['multilingual'] = array(
'#type' => 'radios',
'#title' => t('Multilingual support'),
'#description' => t('If <em>Entity translation</em> is enabled it will be possible to provide a different version of the same product for each available language.') . '<br />' . t('You can find more options in the <a href="!url">entity translation settings</a>.', array(
'!url' => url('admin/config/regional/entity_translation'),
)) . '<br />' . t('Existing products will not be affected by changing this option.'),
'#options' => array(
0 => t('Disabled'),
ENTITY_TRANSLATION_ENABLED => t('Enabled via <em>Entity translation</em>'),
),
'#default_value' => variable_get('language_product_type_' . $product_type['type'], 0),
);
}
$form['actions'] = array(
'#type' => 'actions',
'#weight' => 40,
);
// We add the form's #submit array to this button along with the actual submit
// handler to preserve any submit handlers added by a form callback_wrapper.
$submit = array();
if (!empty($form['#submit'])) {
$submit += $form['#submit'];
}
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save product type'),
'#submit' => array_merge($submit, array(
'commerce_product_ui_product_type_form_submit',
)),
);
if (!empty($form_state['product_type']['type'])) {
$form['actions']['delete'] = array(
'#type' => 'submit',
'#value' => t('Delete product type'),
'#suffix' => l(t('Cancel'), 'admin/commerce/products/types'),
'#submit' => array_merge($submit, array(
'commerce_product_ui_product_type_form_delete_submit',
)),
'#weight' => 45,
);
}
else {
$form['actions']['save_continue'] = array(
'#type' => 'submit',
'#value' => t('Save and add fields'),
'#suffix' => l(t('Cancel'), 'admin/commerce/products/types'),
'#submit' => array_merge($submit, array(
'commerce_product_ui_product_type_form_submit',
)),
'#weight' => 45,
);
}
$form['#validate'][] = 'commerce_product_ui_product_type_form_validate';
return $form;
}