It would appear that there are methods available on BundleFieldDefinition::create() that don't actually do anything. Take the following

/**
 * Provides an entity trait for Commerce Order Item entities.
 *
 * @CommerceEntityTrait(
 *  id = "commerce_recurly_plan_code",
 *  label = @Translation("Provides a Recurly Subscription based on its Plan Code."),
 *  entity_types = {"commerce_product_variation"}
 * )
 */
class RecurlyPlanVariation extends EntityTraitBase {

  /**
   * {@inheritdoc}
   */
  public function buildFieldDefinitions() {
    // Builds the field definitions.
    $fields = [];
    $fields['plan_code'] = BundleFieldDefinition::create('string')
      ->setLabel(t('Recurly Plan Code'))
      ->setDescription(t('The Plan Code of the related Recurly plan.')) // Doesn't apply
      ->setCardinality(1)
      ->setRequired(TRUE)
      ->setDisplayConfigurable('form', FALSE)
      ->setDisplayConfigurable('view', FALSE);
      ->addConstraint('RecurlyPlanCodeExists', []); // Doesn't apply
    return $fields;
  }

}

In this case, neither the description or the constraint are added to the field definition, and there's no notice given that this is happening. They must be added in hook__entity_bundle_field_info_alter() in order to have any effect on the field in question.

Comments

mrweiner created an issue.

dawehner’s picture

@mrweiner Do you fully understand why this is the case?

mrweiner’s picture

@dawehner it's been a while since I looked at this so don't recall. But no, I don't think I fully figured out why this is the case.