You are here

public function DateExampleMigration::prepareRow in Date 8

Same name and namespace in other branches
  1. 7.3 tests/date_migrate_test/date_migrate_test.migrate.inc \DateExampleMigration::prepareRow()
  2. 7.2 tests/date_migrate_test/date_migrate_test.migrate.inc \DateExampleMigration::prepareRow()

Transforms the raw migration data into the expected date formats.

An advanced feature of the date field handler is that in addition to the basic (Start) date itself, we can add additional properties like timezone, encapsulating them as JSON.

File

date_migrate/date_migrate_example/date_migrate_example.migrate.inc, line 100
Examples and test folder for migration into date fields.

Class

DateExampleMigration
Migration class to test import of various date fields.

Code

public function prepareRow($current_row) {

  // The date range field can have multiple values.
  $current_row->date_range_from = array();
  foreach ($current_row->xml->date_range as $range) {
    $date_data = array(
      'from' => (string) $range->from[0],
      'to' => (string) $range->to[0],
    );
    $current_row->date_range_from[] = drupal_json_encode($date_data);
  }
  $date_data = array(
    'from' => (string) $current_row->xml->datestamp_range->from[0],
    'to' => (string) $current_row->xml->datestamp_range->to[0],
  );
  $current_row->datestamp_range_from = drupal_json_encode($date_data);
  $date_data = array(
    'from' => (string) $current_row->xml->datetime_range->from[0],
    'to' => (string) $current_row->xml->datetime_range->to[0],
    'timezone' => (string) $current_row->xml->datetime_range->timezone[0],
  );
  $current_row->datetime_range_from = drupal_json_encode($date_data);
  $date_data = array(
    'from' => (string) $current_row->xml->date_repeat->date[0],
    'rrule' => (string) $current_row->xml->date_repeat->rule[0],
  );
  $current_row->date_repeat = drupal_json_encode($date_data);
}