function hook_commerce_bpc_token_sample_values in Commerce Bulk Product Creation 7
Same name and namespace in other branches
- 7.2 commerce_bpc.api.php \hook_commerce_bpc_token_sample_values()
Provide example values of the tokens corresponding to an instance.
A module that manages a field instance for combination-creation should use this hook to provide example values for the two tokens managed by commerce_bpc (the 'label' and 'value' tokens).
These example values are used, for example, to provide live previews the SKU and title of the products to be generated.
Parameters
array $instance: An array holding the instance info for which example values should be returned.
Return value
array An array with two keys 'label' and 'value', holding an example value for each.
See also
2 functions implement hook_commerce_bpc_token_sample_values()
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
- bpc_taxonomy_commerce_bpc_token_sample_values in modules/
bpc_taxonomy/ bpc_taxonomy.module - Implements hook_commerce_bpc_token_sample_values().
- commerce_bpc_commerce_bpc_token_sample_values in ./
commerce_bpc.hooks_list.inc - Implements hook_commerce_bpc_token_sample_values().
2 invocations of hook_commerce_bpc_token_sample_values()
- commerce_bpc_token_info_by_product_type in ./
commerce_bpc.tokens.inc - Collects field-specific tokens for a given product type.
- commerce_bpc_token_sample_values in ./
commerce_bpc.tokens.inc - Collects sample values of tokens for a given product type.
File
- ./
commerce_bpc.api.php, line 342 - This file contains no working PHP code; it exists to provide additional documentation for doxygen as well as to document hooks in the standard Drupal manner.
Code
function hook_commerce_bpc_token_sample_values($instance) {
$samples = array();
$field_name = $instance['field_name'];
$field = field_info_field($field_name);
if ($field['module'] == 'list') {
$options = list_allowed_values($field);
$values = array_keys($options);
$samples['value'] = array(
LANGUAGE_NONE => array(
array(
'value' => reset($values),
),
),
);
$samples['label'] = reset($options);
}
return $samples;
}