function commerce_license_entity_bundle_field_info_alter in Commerce License 8.2
Implements hook_entity_bundle_field_info_alter().
File
- ./
commerce_license.module, line 35 - Contains commerce_license.module.
Code
function commerce_license_entity_bundle_field_info_alter(&$fields, EntityTypeInterface $entity_type, $bundle) {
// Add constraints to product variations which use subscription licenses.
if ($entity_type
->id() == 'commerce_product_variation' && !empty($fields['subscription_type']) && !empty($fields['license_type'])) {
// Add a constraint to the subscription_type field to ensure that our
// license subscription type can only be used when the license trait is
// also present on the product variation entity.
$fields['subscription_type']
->addConstraint('LicenseSubscriptionType', []);
// Add a constraint to the expiration_type field to ensure that when a
// subscription is used, the expiration is set to 'unlimited'.
$fields['license_expiration']
->addConstraint('LicenseExpirationTypeWithSubscription', []);
}
}