You are here

public function PromotionReport::buildFieldDefinitions in Commerce Reporting 8

Builds the field definitions for entities of this bundle.

Important: Field names must be unique across all bundles. It is recommended to prefix them with the bundle name (plugin ID).

Return value

\Drupal\entity\BundleFieldDefinition[] An array of bundle field definitions, keyed by field name.

Overrides BundlePluginInterface::buildFieldDefinitions

File

src/Plugin/Commerce/ReportType/PromotionReport.php, line 66

Class

PromotionReport
Provide a report for Promotions on behalf of commerce_promotion.

Namespace

Drupal\commerce_reports\Plugin\Commerce\ReportType

Code

public function buildFieldDefinitions() {
  $fields = [];
  $fields['promotion_id'] = BundleFieldDefinition::create('entity_reference')
    ->setLabel(t('Promotion'))
    ->setTargetEntityTypeId('commerce_promotion')
    ->setCardinality(1)
    ->setRequired(TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['promotion_label'] = BundleFieldDefinition::create('string')
    ->setLabel(t('Name'))
    ->setDescription(t('The promotion name.'))
    ->setSettings([
    'default_value' => '',
    'max_length' => 255,
  ]);
  $fields['promotion_amount'] = BundleFieldDefinition::create('commerce_price')
    ->setLabel(t('Promotion amount'))
    ->setCardinality(1)
    ->setRequired(TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['coupon_id'] = BundleFieldDefinition::create('entity_reference')
    ->setLabel(t('Coupon'))
    ->setTargetEntityTypeId('commerce_promotion_coupon')
    ->setCardinality(1)
    ->setRequired(FALSE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['coupon_code'] = BundleFieldDefinition::create('string')
    ->setLabel(t('Coupon code'))
    ->setDescription(t('The unique, machine-readable identifier for a coupon.'))
    ->setRequired(FALSE)
    ->setSettings([
    'default_value' => '',
    'max_length' => 50,
  ]);
  return $fields;
}