You are here

public static function Payment::baseFieldDefinitions in Commerce Core 8.2

Provides base field definitions for an entity type.

Implementations typically use the class \Drupal\Core\Field\BaseFieldDefinition for creating the field definitions; for example a 'name' field could be defined as the following:

$fields['name'] = BaseFieldDefinition::create('string')
  ->setLabel(t('Name'));

By definition, base fields are fields that exist for every bundle. To provide definitions for fields that should only exist on some bundles, use \Drupal\Core\Entity\FieldableEntityInterface::bundleFieldDefinitions().

The definitions returned by this function can be overridden for all bundles by hook_entity_base_field_info_alter() or overridden on a per-bundle basis via 'base_field_override' configuration entities.

Parameters

\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type definition. Useful when a single class is used for multiple, possibly dynamic entity types.

Return value

\Drupal\Core\Field\FieldDefinitionInterface[] An array of base field definitions for the entity type, keyed by field name.

Overrides ContentEntityBase::baseFieldDefinitions

See also

\Drupal\Core\Entity\EntityFieldManagerInterface::getFieldDefinitions()

\Drupal\Core\Entity\FieldableEntityInterface::bundleFieldDefinitions()

File

modules/payment/src/Entity/Payment.php, line 382

Class

Payment
Defines the payment entity class.

Namespace

Drupal\commerce_payment\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
  $fields = parent::baseFieldDefinitions($entity_type);
  $fields['payment_gateway'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Payment gateway'))
    ->setDescription(t('The payment gateway.'))
    ->setRequired(TRUE)
    ->setSetting('target_type', 'commerce_payment_gateway');
  $fields['payment_gateway_mode'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Payment gateway mode'))
    ->setDescription(t('The payment gateway mode.'))
    ->setRequired(TRUE);
  $fields['payment_method'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Payment method'))
    ->setDescription(t('The payment method.'))
    ->setSetting('target_type', 'commerce_payment_method')
    ->setReadOnly(TRUE);
  $fields['order_id'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Order'))
    ->setDescription(t('The parent order.'))
    ->setSetting('target_type', 'commerce_order')
    ->setReadOnly(TRUE);
  $fields['remote_id'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Remote ID'))
    ->setDescription(t('The remote payment ID.'))
    ->setSetting('max_length', 255)
    ->setDisplayConfigurable('view', TRUE);
  $fields['remote_state'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Remote State'))
    ->setDescription(t('The remote payment state.'))
    ->setSetting('max_length', 255)
    ->setDisplayConfigurable('view', TRUE);
  $fields['amount'] = BaseFieldDefinition::create('commerce_price')
    ->setLabel(t('Amount'))
    ->setDescription(t('The payment amount.'))
    ->setRequired(TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['refunded_amount'] = BaseFieldDefinition::create('commerce_price')
    ->setLabel(t('Refunded amount'))
    ->setDescription(t('The refunded payment amount.'))
    ->setDisplayConfigurable('view', TRUE);
  $fields['state'] = BaseFieldDefinition::create('state')
    ->setLabel(t('State'))
    ->setDescription(t('The payment state.'))
    ->setRequired(TRUE)
    ->setSetting('max_length', 255)
    ->setDisplayOptions('view', [
    'label' => 'hidden',
    'type' => 'list_default',
    'weight' => 0,
  ])
    ->setDisplayConfigurable('view', TRUE)
    ->setSetting('workflow_callback', [
    '\\Drupal\\commerce_payment\\Entity\\Payment',
    'getWorkflowId',
  ]);
  $fields['authorized'] = BaseFieldDefinition::create('timestamp')
    ->setLabel(t('Authorized'))
    ->setDescription(t('The time when the payment was authorized.'))
    ->setDisplayConfigurable('view', TRUE);
  $fields['expires'] = BaseFieldDefinition::create('timestamp')
    ->setLabel(t('Expires'))
    ->setDescription(t('The time when the payment expires. 0 for never.'))
    ->setDisplayConfigurable('view', TRUE)
    ->setDefaultValue(0);
  $fields['completed'] = BaseFieldDefinition::create('timestamp')
    ->setLabel(t('Completed'))
    ->setDescription(t('The time when the payment was completed.'))
    ->setDisplayConfigurable('view', TRUE);
  $fields['avs_response_code'] = BaseFieldDefinition::create('string')
    ->setLabel(t('AVS response code'))
    ->setDescription(t('The AVS response code.'))
    ->setDisplayConfigurable('view', TRUE);
  $fields['avs_response_code_label'] = BaseFieldDefinition::create('string')
    ->setLabel(t('AVS response code label'))
    ->setDescription(t('The AVS response code label.'))
    ->setDisplayConfigurable('view', TRUE);

  // These fields have been replaced by payment_gateway_mode and completed.
  // They have been temporarily kept for commerce_payment_post_update_2().
  // They are no longer used and will be removed in Commerce 2.0.
  $fields['test'] = BaseFieldDefinition::create('boolean')
    ->setLabel(t('Test'))
    ->setDescription(t('Whether this is a test payment.'));
  $fields['captured'] = BaseFieldDefinition::create('timestamp')
    ->setLabel(t('Captured'))
    ->setDescription(t('The time when the payment was captured.'))
    ->setDisplayConfigurable('view', TRUE);
  return $fields;
}