I've gotten to a point where I'm having trouble connecting the dots with D8. As a result, I'm not sure I'm even asking the right question.
At this moment, I'm trying to figure out how to add a field to a class that implements
As an example, Commerce License provides an Entity Trait for the
commerce_product_variation entity type.
If the trait is enabled, a field (
license_type) is added to the product variation form - this is done within PurchasableEntityLicensed.php. I want to add an additional field to that, something like:
$fields['license_duration'] = BundleFieldDefinition::create('boolean') ->setLabel(t('License Duration')) ->setCardinality(1) ->setRequired(FALSE) ->setDisplayOptions('form', [ 'type' => 'boolean_checkbox', 'weight' => 21, ]);
If I do that, and add the field to the form (in LicenseCreateForm), check the box on the variation for License Duration I get the following error when trying to save the variation:
Recoverable fatal error: Argument 1 passed to Drupal\commerce_license\Plugin\Commerce\LicenseType\Base::validateConfigurationForm() must be of the type array, null given
I'm not sure if I don't understand plugins well enough, or specifically, field plugins, or maybe Commerce. I don't know what I don't know.
So, to be specific: how am I supposed to add this field so that it works?