function commerce_license_form_views_form_commerce_cart_form_default_alter in Commerce License 7
Implements hook_form_FORM_ID_alter().
Prevents the changing of the license line item quantity on the cart form.
File
- ./
commerce_license.module, line 716 - Provides a framework for selling access to local or remote resources.
Code
function commerce_license_form_views_form_commerce_cart_form_default_alter(&$form, &$form_state) {
if (empty($form['edit_quantity'])) {
// The quantity field is not present on the view.
return;
}
$line_item_types = commerce_license_line_item_types();
$product_types = commerce_license_product_types();
foreach (element_children($form['edit_quantity']) as $key) {
// Modules including commerce_bundle may produce pseudo line items that
// lack a '#line_item_id' property.
if (isset($form['edit_quantity'][$key]['#line_item_id'])) {
$line_item_id = $form['edit_quantity'][$key]['#line_item_id'];
$line_item = commerce_line_item_load($line_item_id);
// Check whether the line item can contain licenses. This also ensures we're
// dealing with a product line item (there's a commerce_product field).
if (in_array($line_item->type, $line_item_types)) {
// Check whether the product is licensable, since the line item might be
// able to hold both licensable and non-licensable products.
$line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
if (in_array($line_item_wrapper->commerce_product->type
->value(), $product_types)) {
$quantity = $form['edit_quantity'][$key]['#default_value'];
$form['edit_quantity'][$key]['#type'] = 'value';
$form['edit_quantity'][$key]['#suffix'] = check_plain($quantity);
}
}
}
}
}