function commerce_license_field_widget_form_alter in Commerce License 7
Same name and namespace in other branches
- 8.2 commerce_license.module \commerce_license_field_widget_form_alter()
Implements hook_field_widget_form_alter().
File
- ./
commerce_license.module, line 951 - Provides a framework for selling access to local or remote resources.
Code
function commerce_license_field_widget_form_alter(&$element, &$form_state, $context) {
$field = $context['field'];
$instance = $context['instance'];
// Hide the license type field if there's only one possible option.
if ($field['field_name'] == 'commerce_license_type') {
$entity_type = $element['#entity_type'];
$entity = $element['#entity'];
$allowed_values = commerce_license_types_allowed_values($field, $instance, $entity_type, $entity);
if (count($allowed_values) == 1) {
$element['#default_value'] = key($allowed_values);
$element['#type'] = 'value';
}
}
}