You are here

function commerce_promotion_entity_base_field_info in Commerce Core 8.2

Implements hook_entity_base_field_info().

1 call to commerce_promotion_entity_base_field_info()
commerce_promotion_post_update_1 in modules/promotion/commerce_promotion.post_update.php
Add the coupons field to orders.

File

modules/promotion/commerce_promotion.module, line 133
Provides a UI for managing promotions.

Code

function commerce_promotion_entity_base_field_info(EntityTypeInterface $entity_type) {
  if ($entity_type
    ->id() == 'commerce_order') {
    $fields['coupons'] = BaseFieldDefinition::create('entity_reference')
      ->setLabel(t('Coupons'))
      ->setDescription(t('Coupons which have been applied to order.'))
      ->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED)
      ->setRequired(FALSE)
      ->setSetting('target_type', 'commerce_promotion_coupon')
      ->setSetting('handler', 'default')
      ->setTranslatable(FALSE)
      ->addConstraint('CouponValid')
      ->setDisplayOptions('form', [
      'type' => 'entity_reference_autocomplete',
      'weight' => 5,
      'settings' => [
        'match_operator' => 'CONTAINS',
        'size' => '60',
        'autocomplete_type' => 'tags',
        'placeholder' => '',
      ],
    ]);
    return $fields;
  }
}