function commerce_backoffice_product_variation_type_form_submit in Commerce Backoffice 7
Form submit handler: save a product variation type.
1 string reference to 'commerce_backoffice_product_variation_type_form_submit'
File
- includes/
commerce_backoffice_product.product_variation_types.inc, line 163 - Product variation specific copy of commerce_product_ui/includes/commerce_product_ui.types.inc and commerce_product_ui/includes/commerce_product_ui.forms.inc.
Code
function commerce_backoffice_product_variation_type_form_submit($form, &$form_state) {
commerce_product_ui_product_type_form_submit($form, $form_state);
if (!empty($form_state['product_type']['type'])) {
$type_name = $form_state['product_type']['type'];
}
else {
$type_name = $form_state['values']['product_type']['type'];
}
$type_name = trim($type_name);
$human_name = trim($form_state['values']['product_type']['name']);
if (!empty($form_state['values']['create_product_display']) && !node_type_load($type_name)) {
// Create the product display type.
$type = node_type_set_defaults();
$type->type = $type_name;
$type->name = $human_name;
$type->custom = TRUE;
$type->base = 'node_content';
$status = node_type_save($type);
// node_type_save doesn't invoke this.
field_attach_create_bundle('node', $type_name);
// Don't display author information
variable_set('node_submitted_' . $type_name, 0);
// Remove promoted to front page.
variable_set('node_options_' . $type_name, array(
'status',
));
$entity_info = entity_get_info('node');
// Update the weight of the "title" field.
if (!empty($entity_info['field replacement'])) {
if ($instance = field_info_instance('node', 'title_field', $type_name)) {
if (isset($instance['display'])) {
foreach ($instance['display'] as $view_mode_key => $view_mode_settings) {
$instance['display'][$view_mode_key]['weight'] = -20;
$instance['display'][$view_mode_key]['type'] = 'title_linked';
$instance['display'][$view_mode_key]['label'] = 'hidden';
$instance['display'][$view_mode_key]['module'] = 'title';
$instance['display'][$view_mode_key]['settings']['title_link'] = 'content';
}
}
field_update_instance($instance);
}
}
// Create the product reference field.
$field = field_info_field('field_product');
if (!$field) {
$field = array(
'field_name' => 'field_product',
'type' => 'commerce_product_reference',
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
'entity_types' => array(
'node',
),
'translatable' => FALSE,
'locked' => FALSE,
);
$field = field_create_field($field);
}
$instance = array(
'field_name' => 'field_product',
'entity_type' => 'node',
'bundle' => $type_name,
'label' => 'Product variations',
'required' => TRUE,
'settings' => array(
'field_injection' => 1,
'referenceable_types' => array(
$type_name => $type_name,
),
'user_register_form' => FALSE,
),
'widget' => array(
'active' => 1,
'module' => 'inline_entity_form',
'settings' => array(
'fields' => array(),
'type_settings' => array(
'allow_existing' => 0,
'autogenerate_title' => 1,
'delete_references' => 1,
'match_operator' => 'CONTAINS',
'use_variation_language' => 1,
),
),
'type' => 'inline_entity_form',
),
'display' => array(
'default' => array(
'label' => 'above',
'module' => 'commerce_cart',
'settings' => array(
'attributes_single' => 1,
'combine' => 1,
'default_quantity' => '1',
'line_item_type' => 'product',
'show_quantity' => 1,
'show_single_product_attributes' => FALSE,
),
'type' => 'commerce_cart_add_to_cart_form',
'weight' => '3',
),
'full' => array(
'label' => 'hidden',
'module' => 'commerce_cart',
'settings' => array(
'combine' => 1,
'default_quantity' => '1',
'line_item_type' => 'product',
'show_quantity' => 1,
'show_single_product_attributes' => FALSE,
),
'type' => 'commerce_cart_add_to_cart_form',
'weight' => '5',
),
),
);
field_create_instance($instance);
}
drupal_get_messages('status', TRUE);
drupal_set_message(t('Product variation type %type saved.', array(
'%type' => $human_name,
)));
if ($form_state['triggering_element']['#parents'][0] == 'save_continue') {
$form_state['redirect'] = 'admin/commerce/config/product-variation-types/' . strtr($type_name, '_', '-') . '/fields';
}
else {
$form_state['redirect'] = 'admin/commerce/config/product-variation-types';
}
}