function commerce_bpc_process_fragment_field in Commerce Bulk Product Creation 7
Same name and namespace in other branches
- 7.2 commerce_bpc.forms.inc \commerce_bpc_process_fragment_field()
Process SKU and title fragment fields.
1 string reference to 'commerce_bpc_process_fragment_field'
- commerce_bpc_create_bulk_form in ./
commerce_bpc.forms.inc - Form constructor for the bulk creation form.
File
- ./
commerce_bpc.forms.inc, line 401 - Form generation functions for the Commerce bulk product creation module
Code
function commerce_bpc_process_fragment_field($element, &$form_state, &$form) {
$product_type = $form['product_type']['#value'];
$tokens = commerce_bpc_token_info_by_product_type($product_type);
$samples = commerce_bpc_token_sample_values($product_type);
$data['bulk_data']['combination'] = $samples['values'];
$data['bulk_data']['product_type'] = $product_type;
switch ($element['#name']) {
case 'sku_fragment':
$pattern = commerce_bpc_setting('default', 'sku_pattern', $product_type);
$token = '[bulk_defaults:entered_sku]';
$target_id = 'sku_example';
$label = t('Example variant SKU:');
break;
case 'title_fragment':
$pattern = commerce_bpc_setting('default', 'title_pattern', $product_type);
$token = '[bulk_defaults:entered_title]';
$target_id = 'title_example';
$label = t('Example variant title:');
break;
}
$pattern = token_replace($pattern, $data, array(
'sanitize' => FALSE,
));
$wrapper_id = $target_id . '_wrapper';
$element['#field_suffix'] = '<small id="' . $wrapper_id . '">' . $label . ' <span id="' . $target_id . '"></span></small>';
$js_settings = array(
'type' => 'setting',
'data' => array(
'commerce_bpc' => array(
'#' . $element['#id'] => array(
'pattern' => $pattern,
'target' => '#' . $target_id,
'target_wrapper' => '#' . $wrapper_id,
'token' => $token,
),
),
),
);
$element['#attached']['js'][] = drupal_get_path('module', 'commerce_bpc') . '/js/pattern.js';
$element['#attached']['js'][] = $js_settings;
return $element;
}