You are here

function commerce_coupon_machine_name_code in Commerce Coupon 7

Generates a machine name for a coupon code.

@retrun string A generated machine name for the coupon code.

Parameters

$coupon: A commerce coupon object

2 calls to commerce_coupon_machine_name_code()
commerce_coupon_commerce_price_component_type_info in ./commerce_coupon.module
Implements hook_commerce_price_component_type_info().
commerce_coupon_get_properties in ./commerce_coupon.module
Callback for getting coupon properties.

File

./commerce_coupon.module, line 880
Coupon System for Drupal Commerce.

Code

function commerce_coupon_machine_name_code($coupon) {
  $coupon_code = $coupon->commerce_coupon_code[LANGUAGE_NONE][0]['value'];

  // Set the pattern replacement to the default one that drupal uses for
  // machine names.
  // @see form_process_machine_name()
  return preg_replace('/_+/', '_', preg_replace('/[^a-z0-9]/', '_', drupal_strtolower($coupon_code)));
}