You are here

function commerce_recurring_update_8101 in Commerce Recurring Framework 8

Add the 'trial_starts' and "trial_ends" fields to subscriptions.

File

./commerce_recurring.install, line 34
Install, update and uninstall functions for the commerce_recurring module.

Code

function commerce_recurring_update_8101(&$sandbox) {
  $fields = [];
  $fields['trial_starts'] = BaseFieldDefinition::create('timestamp')
    ->setLabel(t('Trial starts'))
    ->setDescription(t('The time when the subscription trial starts.'))
    ->setRequired(FALSE)
    ->setDisplayOptions('view', [
    'label' => 'hidden',
    'type' => 'timestamp',
    'weight' => 0,
  ])
    ->setDisplayOptions('form', [
    'type' => 'datetime_timestamp',
    'weight' => 0,
  ])
    ->setDisplayConfigurable('form', TRUE);
  $fields['trial_ends'] = BaseFieldDefinition::create('timestamp')
    ->setLabel(t('Trial ends'))
    ->setDescription(t('The time when the subscription trial ends.'))
    ->setRequired(FALSE)
    ->setDisplayOptions('view', [
    'label' => 'hidden',
    'type' => 'timestamp',
    'weight' => 0,
  ])
    ->setDisplayOptions('form', [
    'type' => 'datetime_timestamp',
    'weight' => 0,
  ])
    ->setDisplayConfigurable('form', TRUE);
  $update_manager = \Drupal::entityDefinitionUpdateManager();
  foreach ($fields as $name => $storage_definition) {
    $update_manager
      ->installFieldStorageDefinition($name, 'commerce_subscription', 'commerce_recurring', $storage_definition);
  }
}