public function CreditCard::buildFieldDefinitions in Commerce Core 8.2
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 PaymentMethodTypeBase::buildFieldDefinitions
File
- modules/
payment/ src/ Plugin/ Commerce/ PaymentMethodType/ CreditCard.php, line 34
Class
- CreditCard
- Provides the credit card payment method type.
Namespace
Drupal\commerce_payment\Plugin\Commerce\PaymentMethodTypeCode
public function buildFieldDefinitions() {
$fields = parent::buildFieldDefinitions();
$fields['card_type'] = BundleFieldDefinition::create('list_string')
->setLabel(t('Card type'))
->setDescription(t('The credit card type.'))
->setRequired(TRUE)
->setSetting('allowed_values_function', [
'\\Drupal\\commerce_payment\\CreditCard',
'getTypeLabels',
]);
$fields['card_number'] = BundleFieldDefinition::create('string')
->setLabel(t('Card number'))
->setDescription(t('The last few digits of the credit card number'))
->setRequired(TRUE);
// card_exp_month and card_exp_year are not required because they might
// not be known (tokenized non-reusable payment methods).
$fields['card_exp_month'] = BundleFieldDefinition::create('integer')
->setLabel(t('Card expiration month'))
->setDescription(t('The credit card expiration month.'))
->setSetting('size', 'tiny');
$fields['card_exp_year'] = BundleFieldDefinition::create('integer')
->setLabel(t('Card expiration year'))
->setDescription(t('The credit card expiration year.'))
->setSetting('size', 'small');
return $fields;
}