You are here

public function DateField::getFieldType in Drupal 10

Computes the destination type of a migrated field.

Parameters

\Drupal\migrate\Row $row: The field being migrated.

Return value

string The destination field type.

Overrides FieldPluginBase::getFieldType

File

core/modules/datetime/src/Plugin/migrate/field/DateField.php, line 118

Class

DateField
Provides a field plugin for date and time fields.

Namespace

Drupal\datetime\Plugin\migrate\field

Code

public function getFieldType(Row $row) {
  $field_type = parent::getFieldType($row);

  // If the 'todate' setting is specified then change the field type to
  // 'daterange' so we can migrate the end date.
  if ($field_type === 'datetime' && !empty($row
    ->get('settings/todate'))) {
    if (\Drupal::service('module_handler')
      ->moduleExists('datetime_range')) {
      return 'daterange';
    }
    else {
      throw new MigrateException(sprintf("Can't migrate field '%s' with 'todate' settings. Enable the datetime_range module. See https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#datetime", $row
        ->get('field_name')));
    }
  }
  return $field_type;
}