function DateField::getFieldType

Same name in other branches
  1. 9 core/modules/datetime/src/Plugin/migrate/field/DateField.php \Drupal\datetime\Plugin\migrate\field\DateField::getFieldType()
  2. 11.x core/modules/datetime/src/Plugin/migrate/field/DateField.php \Drupal\datetime\Plugin\migrate\field\DateField::getFieldType()

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.