While creating discounts programmatically I checked the column max length so I knew exactly how long I could make the machine name. The current length is 64 and this properly saves. If i then edit that discount through the admin ui i get this error message
Machine-readable name cannot be longer than 23 characters but is currently 25 characters long.
Looking at commerce_discount.admin.inc the maxlength is being restricted to 32 characters rather than 64. Is there a reason for this I'm not seeing? Simply updating #maxlength to 55 resolved the issue for me.
// Machine-readable type name.
$form['name'] = array(
'#type' => 'machine_name',
// Strip the 'discount_' prefix from the beginning of the string
'#default_value' => isset($commerce_discount->name) ? substr($commerce_discount->name, 9) : '',
'#disabled' => $commerce_discount->hasStatus(ENTITY_IN_CODE),
'#machine_name' => array(
'exists' => '_commerce_discount_name_exists',
'source' => array('label'),
),
'#description' => t('A unique machine-readable name for this message type. It must only contain lowercase letters, numbers, and underscores.'),
// 32 characters minus the 'discount_' prefix.
'#maxlength' => 23,
// This field should stay LTR even for RTL languages.
'#field_prefix' => '<span dir="ltr">discount_',
'#field_suffix' => '</span>‎',
);
Another potential problem is the maxlength offset is hardcoded. Would this cause an issue with a different discount type being created with the api having a different length prefix?
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | discount_name_property-2455069-3.patch | 820 bytes | joelpittet |
Comments
Comment #1
agn507 commentedComment #2
agn507 commentedComment #3
joelpittetI can't see why not. Here's a patch to make it quite evident.
Comment #4
joelpittetComment #5
joelpittetFix in dev, thanks @agn507