You are here

function commerce_discount_build_rule_machine_name in Commerce Discount 7

Builds a machine name suitable for use as the rule machine name.

Parameters

string $discount_name: The machine-name of the discount to build the rule name for.

Return value

string A machine name to be used as the rule configuration machine name.

2 calls to commerce_discount_build_rule_machine_name()
commerce_discount_build_discount_rules in ./commerce_discount.module
Build the rules configuration for the given discounts.
_commerce_discount_rebuild_rules_config in ./commerce_discount.module
Actually rebuild the defaults of a given entity.

File

./commerce_discount.module, line 1419
Defines the discount and discount offer entities, bundles and functionality.

Code

function commerce_discount_build_rule_machine_name($discount_name) {
  $rule_machine_name = 'commerce_discount_rule_' . $discount_name;

  // Ensure the name isn't too long.
  if (strlen($rule_machine_name) > 64) {

    // Shorten the name but ensure uniqueness by using a hash.
    $hash = crc32($discount_name);
    $rule_machine_name = substr($rule_machine_name, 0, 64 - strlen($hash) - 1) . '_' . $hash;
  }
  return $rule_machine_name;
}