You are here

function commerce_bpc_token_sample_values in Commerce Bulk Product Creation 7.2

Same name and namespace in other branches
  1. 7 commerce_bpc.tokens.inc \commerce_bpc_token_sample_values()

Collects sample values of tokens for a given product type.

Parameters

string $product_type: The product type for whose fields sample values should be returned.

Return value

array An array with entries of the form 'token_name' => 'sample_value'

1 call to commerce_bpc_token_sample_values()
commerce_bpc_process_fragment_field in ./commerce_bpc.forms.inc
Render API callback: Adds js-driven preview to fragment fields.

File

./commerce_bpc.tokens.inc, line 152
Token API implementations for Commerce bulk product creation module.

Code

function commerce_bpc_token_sample_values($product_type) {
  $samples = array();
  $instances = field_info_instances('commerce_product', $product_type);
  foreach ($instances as $instance) {
    if (commerce_bpc_is_combination_field($instance)) {
      $sample = module_invoke_all('commerce_bpc_token_sample_values', $instance);
      $samples['values'][$instance['field_name']] = $sample['value'];
      if (isset($sample['label'])) {
        $samples['labels'][$instance['field_name']] = $sample['label'];
      }
    }
  }
  return $samples;
}